Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Self-Destructing Message Android App Capturing Photos and Videos Taking a Video Using an Intent

Ronald Muller
Ronald Muller
2,430 Points

Setting the video duration limit not working

I have tested this on two devices, HTC One and Galaxy Nexus, both do not limit the duration. HTC One continues past the defined limit and the Galaxy Nexus doesn't record at all. Any ideas on how to rewrite this code to do so across multiple devices/manufactures? (Or am I missing something else here?)

Note: I tried using the API specified constant value in the documentation: "android:intent.extra.finishOnCompletion" in place of "MediaStore.EXTRA_DURATION_LIMIT". They both seem to be interchangeable and perform (or don't perform) the same action(s).

Edit: From what I am finding this seems to be a constant issue. Anyone know a good workaround? Maybe a way to stop the intent after a period of time regardless of the activity?

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

The issue with HTC appears to be a common one. I haven't come across a good workaround in a little bit of research. You might be able to use the MediaRecorder class, though I don't know if its setMaxDuration() method will have the same problem or not: http://developer.android.com/guide/topics/media/camera.html#capture-video

Another not-great workaround is to message the user to record less than 10 seconds and then check the file size once the video is recorded. You could reuse the code we have to check the file size when picking a video from the Gallery.

This could should work on the Galaxy Nexus, though. Do you get any error messages when trying to record video on the Nexus?

Travis Avey
Travis Avey
18,876 Points

I know this is a year old, but I wanted to say that I am having the same issues my Galaxy Nexus (running Cyanogen mod11).

But I did get it to record by setting the quality to high:

takeVideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

It didn't record if I set it to the lowest setting.

I am going to try the MediaRecorder class and see what happens

My video recording limit is also not working. I am using a sony xperia v. it is recording upto 20 sec even if i change from 10s to 5s in the code