0

After recording the video

   mMediaRecorder
      .setOutPutFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());

create the media file

         private static File getOutputMediaFile(int type) {
         File mediaStorageDir = newFile(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), "Pitch");
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("Pitch", "failed to create directory");
            return null;
        }
    }
    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                "VID_" + timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}

I sent the video path with an intent to my video play activity to display the video

         public void RecieveUri() {
          Intent intent = new Intent(this,VideoPlayBackActivity.class);
          vidPath =  getOutputMediaFile(MEDIA_TYPE_VIDEO);
          vidP = vidPath.getAbsolutePath();
          intent.putExtra(EXTRA_MESSAGE,vidP);
          startActivity(intent);
          }

I received the file path checked if it was not empty

          Intent intent = getIntent();
          vidPATH = intent.getStringExtra(CameraActivity.EXTRA_MESSAGE);
          if(vidPATH.isEmpty()){
          Toast.makeText(this,"Error",Toast.LENGTH_SHORT).show();
          }
          else{
          Toast.makeText(this,"Path: "+vidPATH,Toast.LENGTH_SHORT).show();
          }

Then i tried to play the video using media player

        try{
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(vidPATH);

        mMediaPlayer.setSurface(surface);
        mMediaPlayer.setLooping(true);
        mMediaPlayer.prepareAsync();

but it does not play the screen stays black and the log cat says W/System.err: java.io.IOException: setDataSource failed.

jackMa
  • 1
  • 2

0 Answers0