You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
4.7 KiB
111 lines
4.7 KiB
6 years ago
|
---
|
||
|
layout: page
|
||
|
title: "Capturing Media"
|
||
5 years ago
|
description: "Understanding pictures, videos and the snapshot concept"
|
||
6 years ago
|
order: 3
|
||
6 years ago
|
disqus: 1
|
||
6 years ago
|
---
|
||
|
|
||
|
This section introduces some key concepts about media capturing, and about the `Mode` control.
|
||
|
|
||
|
### Mode control
|
||
|
|
||
|
The mode control determines what can be captured with the standard APIs (read below). It can be set through XML
|
||
|
or dynamically changed using `cameraView.setMode()`. The current mode value has a few consequences:
|
||
|
|
||
|
- Sizing: the capture size is chosen among the available picture or video sizes,
|
||
|
depending on the flag, according to the given size selector.
|
||
|
- Capturing: while in picture mode, `takeVideo` will throw an exception.
|
||
|
- Capturing: while in video mode, `takePicture` will throw an exception.
|
||
|
- Permission behavior: when requesting a `video` session, the record audio permission will be requested.
|
||
|
If this is needed, the audio permission should be added to your manifest or the app will crash.
|
||
5 years ago
|
Please read the [permissions page](runtime-permissions).
|
||
6 years ago
|
|
||
|
```java
|
||
|
cameraView.setMode(Mode.PICTURE); // for pictures
|
||
|
cameraView.setMode(Mode.VIDEO); // for video
|
||
|
```
|
||
|
|
||
|
### Capturing media
|
||
|
|
||
|
The library supports 4 capture APIs, two for pictures and two for videos.
|
||
|
|
||
|
- Standard APIs: `takePicture()` and `takeVideo()`. These take a high quality picture or video, depending
|
||
|
on the configuration values that were used. The standard APIs **must** be called in the appropriate `Mode`.
|
||
|
- Snapshot APIs: `takePictureSnapshot()` and `takeVideoSnapshot()`. These take a super fast, reliable
|
||
|
snapshot of the camera preview. The snapshot APIs can be called in any `Mode` (you can snap videos in picture mode).
|
||
|
|
||
|
Beyond being extremely fast, and small in size (though low quality), snapshot APIs have the benefit
|
||
|
that the result is automatically cropped to match the view bounds. This means that, if `CameraView` is square,
|
||
|
resulting snapshots are square as well, no matter what the sensor available sizes are.
|
||
|
|
||
|
|Method|Takes|Quality|Callable in `Mode.PICTURE`|Callable in `Mode.VIDEO`|Auto crop|Output size|
|
||
|
|------|-----|-------|--------------------------|------------------------|---------|-----------|
|
||
|
|`takePicture()`|Pictures|Standard|`yes`|`no`|`no`|That of `setPictureSize`|
|
||
|
|`takeVideo(File)`|Videos|Standard|`no`|`yes`|`no`|That of `setVideoSize`|
|
||
5 years ago
|
|`takePictureSnapshot()`|Pictures|Snapshot|`yes`|`yes`|`yes`|That of the preview stream, [or less](snapshot-size)|
|
||
|
|`takeVideoSnapshot(File)`|Videos|Snapshot|`yes`|`yes`|`yes`|That of the preview stream, [or less](snapshot-size)|
|
||
6 years ago
|
|
||
5 years ago
|
> Please note that the video snaphot features requires:
|
||
|
> - API 18. If called before, it throws
|
||
|
> - An OpenGL preview (see [previews](previews)). If not, it throws
|
||
6 years ago
|
|
||
|
### Capturing pictures while recording
|
||
|
|
||
|
This is allowed at the following conditions:
|
||
|
|
||
|
- `takePictureSnapshot()` is used (no HQ pictures)
|
||
5 years ago
|
- the `GL_SURFACE` preview is used (see [previews](previews))
|
||
6 years ago
|
|
||
|
### Related XML attributes
|
||
|
|
||
|
```xml
|
||
|
<com.otaliastudios.cameraview.CameraView
|
||
|
app:cameraMode="picture|video"/>
|
||
|
```
|
||
|
|
||
5 years ago
|
### Related callbacks
|
||
|
|
||
|
```java
|
||
|
camera.addCameraListener(new CameraListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onPictureTaken(@NonNull PictureResult result) {
|
||
|
// A Picture was taken!
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onVideoTaken(@NonNull VideoResult result) {
|
||
|
// A Video was taken!
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onVideoRecordingStart() {
|
||
|
// Notifies that the actual video recording has started.
|
||
|
// Can be used to show some UI indicator for video recording or counting time.
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onVideoRecordingEnd() {
|
||
|
// Notifies that the actual video recording has ended.
|
||
|
// Can be used to remove UI indicators added in onVideoRecordingStart.
|
||
|
}
|
||
|
})
|
||
|
```
|
||
|
|
||
6 years ago
|
### Related APIs
|
||
|
|
||
|
|Method|Description|
|
||
|
|------|-----------|
|
||
|
|`setMode()`|Either `Mode.VIDEO` or `Mode.PICTURE`.|
|
||
|
|`isTakingVideo()`|Returns true if the camera is currently recording a video.|
|
||
|
|`isTakingPicture()`|Returns true if the camera is currently capturing a picture.|
|
||
|
|`takePicture()`|Takes a high quality picture.|
|
||
|
|`takeVideo(File)`|Takes a high quality video.|
|
||
6 years ago
|
|`takeVideo(File, long)`|Takes a high quality video, stopping after the given duration.|
|
||
6 years ago
|
|`takePictureSnapshot()`|Takes a picture snapshot.|
|
||
|
|`takeVideoSnapshot(File)`|Takes a video snapshot.|
|
||
6 years ago
|
|`takeVideoSnapshot(File, long)`|Takes a video snapshot, stopping after the given duration.|
|
||
6 years ago
|
|`getPictureSize()`|Returns the output picture size, accounting for any rotation. Null while in `VIDEO` mode.|
|
||
|
|`getVideoSize()`|Returns the output video size, accounting for any rotation. Null while in `PICTURE` mode.|
|
||
|
|`getSnapshotSize()`|Returns the size of pictures taken with `takePictureSnapshot()` or videos taken with `takeVideoSnapshot()`. Accounts for rotation and cropping.|
|