Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Digma Jain
Digma Jain
1,602 Points

Crashed Video

When I take a Video it is Captured, But when I try to play it the Video Crashes..:(

Justin Horner
Justin Horner
Treehouse Guest Teacher

Hello Digma,

If you would, please post your code and provide the error message(s) so it will be easier for us to help you :)

3 Answers

Digma Jain
Digma Jain
1,602 Points

Hi justin, This My code:

                               case 1:
              Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
               mMediaUri = getOutputMediaFileUri(MEDIA_VIDEO);

               if(mMediaUri == null)

               {//Display Error

                   Toast.makeText
                   (MainActivity.this, "There was A Problem Accessing Your external storage device", Toast.LENGTH_LONG).show();

               }

               else

               {

                   videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);

                   videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);

                   videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);

                   startActivityForResult(videoIntent,TAKE_VIDEO_REQUEST );

               }

This is my code to take Video. And when I try to watch the Video After Capturing the Video Is Crashed..

Saleban Olow
PLUS
Saleban Olow
Courses Plus Student 141 Points

This is how I did and it works fine,

case 1: // take video Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); if(mMediaUri == null){ // display an error

                    Toast.makeText(MainActivity.this, R.string.error_external_storage, 
                            Toast.LENGTH_LONG).show();

                }
                else{
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                    takeVideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
                    takeVideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                    startActivityForResult(takeVideoIntent, TAKE_VIDEO_REQUEST);

                }
                break;

instead using "videoIntent" change to takeVideoIntent...

In my case I was using Genymotion and it sometimes stops generating dummy images for camera. I restarted the emulator and it didn't crash anymore.