use of android.view.SurfaceHolder.Callback in project Osmand by osmandapp.
the class AudioVideoNotesPlugin method takePhotoWithCamera.
private void takePhotoWithCamera(final double lat, final double lon, final MapActivity mapActivity) {
try {
lastTakingPhoto = getBaseFileName(lat, lon, app, IMG_EXTENSION);
final Camera.Size mPreviewSize;
Parameters parameters = cam.getParameters();
List<Camera.Size> psps = parameters.getSupportedPictureSizes();
int camPicSizeIndex = AV_CAMERA_PICTURE_SIZE.get();
// camera picture size
log.debug("takePhotoWithCamera() index=" + camPicSizeIndex);
if (camPicSizeIndex == AV_PHOTO_SIZE_DEFAULT) {
camPicSizeIndex = cameraPictureSizeDefault;
log.debug("takePhotoWithCamera() Default value of picture size. Set index to cameraPictureSizeDefault. Now index=" + camPicSizeIndex);
}
final Camera.Size selectedCamPicSize = psps.get(camPicSizeIndex);
if (mSupportedPreviewSizes != null) {
int width = selectedCamPicSize.width;
int height = selectedCamPicSize.height;
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
} else {
mPreviewSize = null;
}
final SurfaceView view;
if (mPreviewSize != null) {
view = recordingMenu.prepareSurfaceView(mPreviewSize.width, mPreviewSize.height);
} else {
view = recordingMenu.prepareSurfaceView();
}
view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
view.getHolder().addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
// load sound befor shot
if (AV_PHOTO_PLAY_SOUND.get()) {
if (sp == null)
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
if (shotId == 0) {
try {
AssetFileDescriptor assetFileDescriptor = app.getAssets().openFd("sounds/camera_click.ogg");
shotId = sp.load(assetFileDescriptor, 1);
assetFileDescriptor.close();
} catch (Exception e) {
log.error("cannot get shotId for sounds/camera_click.ogg");
}
}
}
Parameters parameters = cam.getParameters();
parameters.setPictureSize(selectedCamPicSize.width, selectedCamPicSize.height);
log.debug("takePhotoWithCamera() set Picture size: width=" + selectedCamPicSize.width + " height=" + selectedCamPicSize.height);
// camera focus type
autofocus = true;
parameters.removeGpsData();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
parameters.setGpsLatitude(lat);
parameters.setGpsLongitude(lon);
}
switch(AV_CAMERA_FOCUS_TYPE.get()) {
case AV_CAMERA_FOCUS_HIPERFOCAL:
parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
autofocus = false;
log.info("Osmand:AudioNotes set camera FOCUS_MODE_FIXED");
break;
case AV_CAMERA_FOCUS_EDOF:
parameters.setFocusMode(Parameters.FOCUS_MODE_EDOF);
autofocus = false;
log.info("Osmand:AudioNotes set camera FOCUS_MODE_EDOF");
break;
case AV_CAMERA_FOCUS_INFINITY:
parameters.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
autofocus = false;
log.info("Osmand:AudioNotes set camera FOCUS_MODE_INFINITY");
break;
case AV_CAMERA_FOCUS_MACRO:
parameters.setFocusMode(Parameters.FOCUS_MODE_MACRO);
log.info("Osmand:AudioNotes set camera FOCUS_MODE_MACRO");
break;
case AV_CAMERA_FOCUS_CONTINUOUS:
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
log.info("Osmand:AudioNotes set camera FOCUS_MODE_CONTINUOUS_PICTURE");
break;
default:
parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
log.info("Osmand:AudioNotes set camera FOCUS_MODE_AUTO");
break;
}
if (parameters.getSupportedWhiteBalance() != null && parameters.getSupportedWhiteBalance().contains(Parameters.WHITE_BALANCE_AUTO)) {
parameters.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
}
if (parameters.getSupportedFlashModes() != null && parameters.getSupportedFlashModes().contains(Parameters.FLASH_MODE_AUTO)) {
// parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
}
int cameraOrientation = getCamOrientation(mapActivity, Camera.CameraInfo.CAMERA_FACING_BACK);
cam.setDisplayOrientation(cameraOrientation);
parameters.set("rotation", cameraOrientation);
if (mPreviewSize != null) {
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
}
cam.setParameters(parameters);
cam.setPreviewDisplay(holder);
cam.startPreview();
internalShoot();
} catch (Exception e) {
logErr(e);
closeRecordingMenu();
closeCamera();
finishRecording();
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
});
recordingMenu.show();
} catch (RuntimeException e) {
logErr(e);
closeCamera();
}
}
use of android.view.SurfaceHolder.Callback in project libstreaming by fyhertz.
the class VideoStream method setSurfaceView.
/**
* Sets a Surface to show a preview of recorded media (video).
* You can call this method at any time and changes will take effect next time you call {@link #start()}.
*/
public synchronized void setSurfaceView(SurfaceView view) {
mSurfaceView = view;
if (mSurfaceHolderCallback != null && mSurfaceView != null && mSurfaceView.getHolder() != null) {
mSurfaceView.getHolder().removeCallback(mSurfaceHolderCallback);
}
if (mSurfaceView != null && mSurfaceView.getHolder() != null) {
mSurfaceHolderCallback = new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mSurfaceReady = false;
stopPreview();
Log.d(TAG, "Surface destroyed !");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mSurfaceReady = true;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.d(TAG, "Surface Changed !");
}
};
mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
mSurfaceReady = true;
}
}
use of android.view.SurfaceHolder.Callback in project Osmand by osmandapp.
the class AudioVideoNotesPlugin method recordVideoCamera.
public void recordVideoCamera(final double lat, final double lon, final MapActivity mapActivity) {
final CamcorderProfile p = CamcorderProfile.get(AV_VIDEO_QUALITY.get());
final Camera.Size mPreviewSize = getPreviewSize();
final SurfaceView view;
if (mPreviewSize != null) {
view = recordingMenu.prepareSurfaceView(mPreviewSize.width, mPreviewSize.height);
} else {
view = recordingMenu.prepareSurfaceView();
}
view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
view.getHolder().addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
MediaRecorder mr = new MediaRecorder();
try {
startCamera(mPreviewSize, holder);
cam.unlock();
mr.setCamera(cam);
} catch (Exception e) {
logErr(e);
closeRecordingMenu();
closeCamera();
finishRecording();
return;
}
final File f = getBaseFileName(lat, lon, app, MPEG4_EXTENSION);
initMediaRecorder(mr, p, f);
try {
if (AV_RECORDER_SPLIT.get()) {
cleanupSpace();
}
runMediaRecorder(mapActivity, mr, f);
} catch (Exception e) {
logErr(e);
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
});
recordingMenu.show();
}
Aggregations