Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After captured Image or recorded video #9

Closed
mskocabay opened this issue Nov 22, 2018 · 4 comments
Closed

After captured Image or recorded video #9

mskocabay opened this issue Nov 22, 2018 · 4 comments

Comments

@mskocabay
Copy link

mskocabay commented Nov 22, 2018

After completed camera operations , I want to show image or video in other actvity .
Is that true ?

In PhotographerActivity.java i added to announcingNewFile method these codes. Is it enogh or must i do something about stop camera or backgroundtasks?

Thank you

            ` private void announcingNewFile(String filePath) {
	Toast.makeText(PhotographerActivity.this, "File: " + filePath, Toast.LENGTH_SHORT).show();
	Utils.addMediaToGallery(PhotographerActivity.this, filePath);
	
	finish();

	try {
		Thread.sleep(500);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}


	Intent intent = new Intent(PhotographerActivity.this,PreviewActivity.class);
	intent.putExtra("mode",0);
	intent.putExtra("file",filePath);
	startActivity(intent);

}`
@duanhong169
Copy link
Owner

The PhotographerActivity.onPause() method stops the camera and background tasks for you:

protected void onPause() {
finishRecordingIfNeeded();
photographer.stopPreview();
super.onPause();
}

So if you have kept the onPause() implementation, then there is no need to do it anymore.

@mskocabay mskocabay reopened this Nov 23, 2018
@mskocabay
Copy link
Author

mskocabay commented Nov 23, 2018

Thank you very much , it is best camera2 example. I tried it but returns this error in andoid 6

FATAL EXCEPTION: main
Process: arge.aa.com.myapplication, PID: 10109
java.lang.RuntimeException: Unable to pause activity {com.camera.myapplication/arge.aa.com.myapplication.PhotographerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean

and in android 8

FATAL EXCEPTION: main
Process: arge.aa.com.myapplication, PID: 19986
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Handler.post(java.lang.Runnable)' on a null object reference
at arge.aa.com.myapplication.Camera2Photographer$4.onImageAvailable(Camera2Photographer.java:195)
at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:812)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

@duanhong169
Copy link
Owner

Seems that the onShotFinished() is called too early, and the image is not finished saving at that time:

@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
unlockFocus();
callbackHandler.onShotFinished(nextImageAbsolutePath);
}

then when the ImageSaver try to save the image, the backgroundHandler has been set to null by onPause():

private final ImageReader.OnImageAvailableListener onImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
backgroundHandler.post(new ImageSaver(reader.acquireLatestImage(), nextImageAbsolutePath));
}
};

I think we could try to put the event:

callbackHandler.onShotFinished(nextImageAbsolutePath);

after:

backgroundHandler.post(new ImageSaver(reader.acquireLatestImage(), nextImageAbsolutePath));

@mskocabay I'm sorry I have no enough time to debug this issue, could you please try to solve this by your own and it's much better if you can create a pull request if applicable.

@mskocabay
Copy link
Author

ok thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants