1. Are you ready for the Galaxy S20? Here is everything we know so far!

Cannot play video recorded on SD card from Android application on PC?

Discussion in 'Android Development' started by litterbug_kid, Dec 22, 2011.

  1. litterbug_kid

    litterbug_kid Lurker
    Thread Starter

    I have managed to take a video in my application and save it to a folder on my SD card, but when I check the SD card and play it on my PC it doesn't seem to play, it's just a black screen! The video is also 0KB. I'm using API 8 and above and I've tried saving it as .mpeg, .3gp and .mp4. My video activity is the same as my camera activity (which works perfectly) except I've changed all the camera type arguments to video arguments.
    Code (Text):
    1. public class VideoActivity extends Activity
    2. {
    3.  
    4.     final int VIDEO_ACTIVITY = 1;
    5.  
    6.     @Override
    7.     public void onCreate(Bundle savedInstanceState)
    8.     {  
    9.         super.onCreate(savedInstanceState);
    10.  
    11.         Intent h = getIntent();
    12.         String filename = h.getStringExtra("string") + ".mpeg";
    13.  
    14.         String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) + "/" + getString(R.string.app_name)+ "/";
    15.         File newdir = new File(dir);
    16.         try{
    17.             newdir.mkdirs();
    18.         }
    19.         catch(Exception e){}
    20.         String file = dir + filename;
    21.         File newfile = new File(file);
    22.         try {
    23.             newfile.delete();
    24.             newfile.createNewFile();
    25.         } catch (IOException e) {}      
    26.  
    27.         Uri outputFileUri = Uri.fromFile(newfile);
    28.         Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    29.         videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    30.         startActivityForResult(videoIntent, VIDEO_ACTIVITY);
    31.     }
    32. }
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...