-
-
Notifications
You must be signed in to change notification settings - Fork 946
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
Max video file size #104
Max video file size #104
Conversation
Nice job, thanks! I'll take a look now. But we can't change the signature of the listener. That would force everyone to rewrite their code. So I think you should revert that, for now the user can manually check the video size. The rest seems like cool additions! |
Codecov Report
|
switch (i){ | ||
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:{ | ||
mHasReachedMaxSize = true; | ||
endVideo(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think endVideoImmediately
would work better.
// Additional helper info | ||
|
||
@Override | ||
boolean isRecordingVideo() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this to CameraController
and make it final
? So Camera1 just inherits.
*/ | ||
@UiThread | ||
public void onVideoTaken(File video) { | ||
public void onVideoTaken(File video, boolean hasReachedMaxFileSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said, I think this is unacceptable at the moment. We can't force everyone to rewrite their code. But in the future I will change the signature with a VideoResult
so we can add everything.
@@ -1346,7 +1364,7 @@ public boolean getPlaySounds() { | |||
void onShutter(boolean shouldPlaySound); | |||
void processImage(byte[] jpeg, boolean consistentWithView, boolean flipHorizontally); | |||
void processSnapshot(YuvImage image, boolean consistentWithView, boolean flipHorizontally); | |||
void dispatchOnVideoTaken(File file); | |||
void dispatchOnVideoTaken(File file, boolean hasReachedMaxFileSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, we can't do this right now.
* | ||
* @param maxFileSizeInBytes The maximum size of videos in bytes | ||
*/ | ||
public void setMaxFileSize(long maxFileSizeInBytes){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename to setVideoMaxSize
?
@natario1 Ya I agree. I was on the fence about that and did not quite like changing the signature. How about adding a new callback method to notify file size limits? That way only people requiring a notification can override it. |
That would be better but I prefer not doing it. You know, there is a lot of video metadata which would be cool to pass around, but we can't have a callback for everything only to deprecate them later. The good solution is really to change the signature as you did with a |
@natario1 Ya makes sense to me. I reverted the changes to the method signature. Please take a look! |
Looks good to me. I will add tests for this later. Two things,
If you don't want to, no problem. |
And, since all video API use |
@natario1 Sure, I'll make the changes |
I'm afraid this feature is a bit problematic, isn't it? I was thinking about implementing the same for the |
A bit hacky, but maybe you could listen to the |
@Johnson145 I have not tried of course but I think the two issues solve each other. When we get the callback the recorder is about to auto-stop. We anticipate and stop it, then notify the user. If it stops itself before we do, there should be no problem because our stopping is in a Does this make sense to you? The best thing would be to try but I'm not able right now. Maybe after it's merged. If it proves to be flaky, we can do the trick with 90%, seems good! Or @chaitanyaraghav can implement it now if he wants. Just be sure to add some code comments about it. These APIs do really suck. |
May work, I don't know. Depends on the question whether the Sure, we could try it first! |
Maybe it's even a good idea to give it a try first. If it proves to work, we could implement the |
Yes, given how unfriendly MediaRecorder is, issues might be likely. The max duration feature would be cool as well if you want to work on it! We could then deprecate startCapturingVideo(File, long). |
@chaitanyaraghav are you planning to work on this soon? There's no hurry of course, I want to know if I should release 1.4.1 today or wait for you. This Sunday I'll leave for a while so it will be hard for me to add tests etc. Thanks so much! |
@natario1 It may be better to push this to the next release. I'm currently out of town and I won't be able to make the changes until I get back this Sunday. |
That's fine man 👍 I'll release today then! |
…updated the documentation
@natario1 Changed the method name, added xml attribute for video size and updated the documentation. The 90% trick seems good but I have not made that change yet. The current implementation appears to work fine in my testing. If it turns out to be flaky, I'll make the change to scale the max size. Thanks for the patience! |
Thanks! |
Hello,
I had a need to set a max file size limit for my implementation of the camera and added the API to set a limit. I added a new API method
setMaxFileSize(long maxFileSizeInBytes)
to set a custom maximum file size for a video recording. The camera ignores the max file size if its not set or is invalid.I added another boolean parameter to the video callback method indicating if the video ended due to a file size limit. I also included a helper getter method to get the status of the current camera video recording. It felt easier as I could rely on
cameraView.isRecordingVideo()
instead of having my own boolean tracking in my activity.Thanks!