@ -107,6 +107,9 @@ public class CameraView extends FrameLayout {
SessionType sessionType = SessionType . fromValue ( a . getInteger ( R . styleable . CameraView_cameraSessionType , SessionType . DEFAULT . value ( ) ) ) ;
SessionType sessionType = SessionType . fromValue ( a . getInteger ( R . styleable . CameraView_cameraSessionType , SessionType . DEFAULT . value ( ) ) ) ;
Hdr hdr = Hdr . fromValue ( a . getInteger ( R . styleable . CameraView_cameraHdr , Hdr . DEFAULT . value ( ) ) ) ;
Hdr hdr = Hdr . fromValue ( a . getInteger ( R . styleable . CameraView_cameraHdr , Hdr . DEFAULT . value ( ) ) ) ;
Audio audio = Audio . fromValue ( a . getInteger ( R . styleable . CameraView_cameraAudio , Audio . DEFAULT . value ( ) ) ) ;
Audio audio = Audio . fromValue ( a . getInteger ( R . styleable . CameraView_cameraAudio , Audio . DEFAULT . value ( ) ) ) ;
VideoCodec codec = VideoCodec . fromValue ( a . getInteger ( R . styleable . CameraView_cameraVideoCodec , VideoCodec . DEFAULT . value ( ) ) ) ;
long videoMaxSize = ( long ) a . getFloat ( R . styleable . CameraView_cameraVideoMaxSize , 0 ) ;
int videoMaxDuration = a . getInteger ( R . styleable . CameraView_cameraVideoMaxDuration , 0 ) ;
// Size selectors
// Size selectors
List < SizeSelector > constraints = new ArrayList < > ( 3 ) ;
List < SizeSelector > constraints = new ArrayList < > ( 3 ) ;
@ -145,9 +148,6 @@ public class CameraView extends FrameLayout {
GestureAction scrollHorizontalGesture = GestureAction . fromValue ( a . getInteger ( R . styleable . CameraView_cameraGestureScrollHorizontal , GestureAction . DEFAULT_SCROLL_HORIZONTAL . value ( ) ) ) ;
GestureAction scrollHorizontalGesture = GestureAction . fromValue ( a . getInteger ( R . styleable . CameraView_cameraGestureScrollHorizontal , GestureAction . DEFAULT_SCROLL_HORIZONTAL . value ( ) ) ) ;
GestureAction scrollVerticalGesture = GestureAction . fromValue ( a . getInteger ( R . styleable . CameraView_cameraGestureScrollVertical , GestureAction . DEFAULT_SCROLL_VERTICAL . value ( ) ) ) ;
GestureAction scrollVerticalGesture = GestureAction . fromValue ( a . getInteger ( R . styleable . CameraView_cameraGestureScrollVertical , GestureAction . DEFAULT_SCROLL_VERTICAL . value ( ) ) ) ;
//Get max size
float cameraVideoMaxSize = a . getFloat ( R . styleable . CameraView_cameraVideoMaxSize , - 1 ) ;
a . recycle ( ) ;
a . recycle ( ) ;
// Components
// Components
@ -182,6 +182,9 @@ public class CameraView extends FrameLayout {
setHdr ( hdr ) ;
setHdr ( hdr ) ;
setAudio ( audio ) ;
setAudio ( audio ) ;
setPictureSize ( selector ) ;
setPictureSize ( selector ) ;
setVideoCodec ( codec ) ;
setVideoMaxSize ( videoMaxSize ) ;
setVideoMaxDuration ( videoMaxDuration ) ;
// Apply gestures
// Apply gestures
mapGesture ( Gesture . TAP , tapGesture ) ;
mapGesture ( Gesture . TAP , tapGesture ) ;
@ -190,11 +193,6 @@ public class CameraView extends FrameLayout {
mapGesture ( Gesture . SCROLL_HORIZONTAL , scrollHorizontalGesture ) ;
mapGesture ( Gesture . SCROLL_HORIZONTAL , scrollHorizontalGesture ) ;
mapGesture ( Gesture . SCROLL_VERTICAL , scrollVerticalGesture ) ;
mapGesture ( Gesture . SCROLL_VERTICAL , scrollVerticalGesture ) ;
//Set camera video maxSize
if ( cameraVideoMaxSize > 0 ) {
setVideoMaxSize ( ( long ) cameraVideoMaxSize ) ;
}
if ( ! isInEditMode ( ) ) {
if ( ! isInEditMode ( ) ) {
mOrientationHelper = new OrientationHelper ( context , mCameraCallbacks ) ;
mOrientationHelper = new OrientationHelper ( context , mCameraCallbacks ) ;
}
}
@ -505,7 +503,9 @@ public class CameraView extends FrameLayout {
case ZOOM :
case ZOOM :
oldValue = mCameraController . getZoomValue ( ) ;
oldValue = mCameraController . getZoomValue ( ) ;
newValue = source . scaleValue ( oldValue , 0 , 1 ) ;
newValue = source . scaleValue ( oldValue , 0 , 1 ) ;
mCameraController . setZoom ( newValue , points , true ) ;
if ( newValue ! = oldValue ) {
mCameraController . setZoom ( newValue , points , true ) ;
}
break ;
break ;
case EXPOSURE_CORRECTION :
case EXPOSURE_CORRECTION :
@ -513,8 +513,10 @@ public class CameraView extends FrameLayout {
float minValue = options . getExposureCorrectionMinValue ( ) ;
float minValue = options . getExposureCorrectionMinValue ( ) ;
float maxValue = options . getExposureCorrectionMaxValue ( ) ;
float maxValue = options . getExposureCorrectionMaxValue ( ) ;
newValue = source . scaleValue ( oldValue , minValue , maxValue ) ;
newValue = source . scaleValue ( oldValue , minValue , maxValue ) ;
float [ ] bounds = new float [ ] { minValue , maxValue } ;
if ( newValue ! = oldValue ) {
mCameraController . setExposureCorrection ( newValue , bounds , points , true ) ;
float [ ] bounds = new float [ ] { minValue , maxValue } ;
mCameraController . setExposureCorrection ( newValue , bounds , points , true ) ;
}
break ;
break ;
}
}
}
}
@ -652,6 +654,8 @@ public class CameraView extends FrameLayout {
setVideoQuality ( ( VideoQuality ) control ) ;
setVideoQuality ( ( VideoQuality ) control ) ;
} else if ( control instanceof WhiteBalance ) {
} else if ( control instanceof WhiteBalance ) {
setWhiteBalance ( ( WhiteBalance ) control ) ;
setWhiteBalance ( ( WhiteBalance ) control ) ;
} else if ( control instanceof VideoCodec ) {
setVideoCodec ( ( VideoCodec ) control ) ;
}
}
}
}
@ -1208,8 +1212,7 @@ public class CameraView extends FrameLayout {
/ * *
/ * *
* Starts recording a video with selected options , in a file called
* Starts recording a video , in a file called "video.mp4" in the default folder .
* "video.mp4" in the default folder .
* This is discouraged , please use { @link # startCapturingVideo ( File ) } instead .
* This is discouraged , please use { @link # startCapturingVideo ( File ) } instead .
*
*
* @deprecated see { @link # startCapturingVideo ( File ) }
* @deprecated see { @link # startCapturingVideo ( File ) }
@ -1221,7 +1224,7 @@ public class CameraView extends FrameLayout {
/ * *
/ * *
* Starts recording a video with selected options . Video will be written to the given file ,
* Starts recording a video . Video will be written to the given file ,
* so callers should ensure they have appropriate permissions to write to the file .
* so callers should ensure they have appropriate permissions to write to the file .
*
*
* @param file a file where the video will be saved
* @param file a file where the video will be saved
@ -1242,27 +1245,29 @@ public class CameraView extends FrameLayout {
/ * *
/ * *
* Starts recording a video with selected options . Video will be written to the given file ,
* Starts recording a video . Video will be written to the given file ,
* so callers should ensure they have appropriate permissions to write to the file .
* so callers should ensure they have appropriate permissions to write to the file .
* Recording will be automatically stopped after durationMillis , unless
* Recording will be automatically stopped after the given duration , overriding
* { @link # stopCapturingVideo ( ) } is not called meanwhile .
* temporarily any duration limit set by { @link # setVideoMaxDuration ( int ) } .
*
*
* @param file a file where the video will be saved
* @param file a file where the video will be saved
* @param durationMillis video max duration
* @param durationMillis recording max duration
*
*
* @throws IllegalArgumentException if durationMillis is less than 500 milliseconds
* @deprecated use { @link # setVideoMaxDuration ( int ) } instead .
* /
* /
@Deprecated
public void startCapturingVideo ( File file , long durationMillis ) {
public void startCapturingVideo ( File file , long durationMillis ) {
if ( durationMillis < 500 ) {
// TODO: v2: change signature to int, or remove (better).
throw new IllegalArgumentException ( "Video duration can't be < 500 milliseconds" ) ;
final int old = getVideoMaxDuration ( ) ;
}
addCameraListener ( new CameraListener ( ) {
startCapturingVideo ( file ) ;
mUiHandler . postDelayed ( new Runnable ( ) {
@Override
@Override
public void run ( ) {
public void onVideoTaken ( File video ) {
stopCapturingVideo ( ) ;
setVideoMaxDuration ( old ) ;
removeCameraListener ( this ) ;
}
}
} , durationMillis ) ;
} ) ;
setVideoMaxDuration ( ( int ) durationMillis ) ;
startCapturingVideo ( file ) ;
}
}
@ -1339,9 +1344,6 @@ public class CameraView extends FrameLayout {
}
}
}
}
//endregion
//region Sounds
@SuppressLint ( "NewApi" )
@SuppressLint ( "NewApi" )
private void playSound ( int soundType ) {
private void playSound ( int soundType ) {
@ -1351,6 +1353,7 @@ public class CameraView extends FrameLayout {
}
}
}
}
/ * *
/ * *
* Controls whether CameraView should play sound effects on certain
* Controls whether CameraView should play sound effects on certain
* events ( picture taken , focus complete ) . Note that :
* events ( picture taken , focus complete ) . Note that :
@ -1364,6 +1367,7 @@ public class CameraView extends FrameLayout {
mCameraController . setPlaySounds ( playSounds ) ;
mCameraController . setPlaySounds ( playSounds ) ;
}
}
/ * *
/ * *
* Gets the current sound effect behavior .
* Gets the current sound effect behavior .
*
*
@ -1374,16 +1378,79 @@ public class CameraView extends FrameLayout {
return mPlaySounds ;
return mPlaySounds ;
}
}
/ * *
/ * *
* Set a max file size ( in bytes ) for a video recording . There is no file size limit by default
* Sets the encoder for video recordings .
* unless set by the user .
* Defaults to { @link VideoCodec # DEVICE_DEFAULT } .
*
* @see VideoCodec # DEVICE_DEFAULT
* @see VideoCodec # H_263
* @see VideoCodec # H_264
*
*
* @param videoMaxSizeInBytes The maximum size of videos in bytes
* @param codec requested video codec
* /
public void setVideoCodec ( VideoCodec codec ) {
mCameraController . setVideoCodec ( codec ) ;
}
/ * *
* Gets the current encoder for video recordings .
* @return the current video codec
* /
* /
public void setVideoMaxSize ( long videoMaxSizeInBytes ) {
public VideoCodec getVideoCodec ( ) {
return mCameraController . getVideoCodec ( ) ;
}
/ * *
* Sets the maximum size in bytes for recorded video files .
* Once this size is reached , the recording will automatically stop .
* Defaults to unlimited size . Use 0 or negatives to disable .
*
* @param videoMaxSizeInBytes The maximum video size in bytes
* /
public void setVideoMaxSize ( long videoMaxSizeInBytes ) {
mCameraController . setVideoMaxSize ( videoMaxSizeInBytes ) ;
mCameraController . setVideoMaxSize ( videoMaxSizeInBytes ) ;
}
}
/ * *
* Returns the maximum size in bytes for recorded video files , or 0
* if no size was set .
*
* @see # setVideoMaxSize ( long )
* @return the maximum size in bytes
* /
public long getVideoMaxSize ( ) {
return mCameraController . getVideoMaxSize ( ) ;
}
/ * *
* Sets the maximum duration in milliseconds for video recordings .
* Once this duration is reached , the recording will automatically stop .
* Defaults to unlimited duration . Use 0 or negatives to disable .
*
* @param videoMaxDurationMillis The maximum video duration in milliseconds
* /
public void setVideoMaxDuration ( int videoMaxDurationMillis ) {
mCameraController . setVideoMaxDuration ( videoMaxDurationMillis ) ;
}
/ * *
* Returns the maximum duration in milliseconds for video recordings , or 0
* if no limit was set .
*
* @see # setVideoMaxDuration ( int )
* @return the maximum duration in milliseconds
* /
public int getVideoMaxDuration ( ) {
return mCameraController . getVideoMaxDuration ( ) ;
}
/ * *
/ * *
* Returns true if the camera is currently recording a video
* Returns true if the camera is currently recording a video
* @return boolean indicating if the camera is recording a video
* @return boolean indicating if the camera is recording a video