Video recorded using MediaRecorder , which is recorded in the application, cannot be played via VideoView .

I write video from the camera like this:

  private boolean prepareVideoRecorder() { camera.unlock(); mediaRecorder = new MediaRecorder(); mediaRecorder.setCamera(camera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mediaRecorder.setProfile(CamcorderProfile .get(CamcorderProfile.QUALITY_HIGH)); mediaRecorder.setOutputFile(getFilesDir().getAbsolutePath() + "/my_video.mp4"); mediaRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface()); try { mediaRecorder.prepare(); } catch (Exception e) { e.printStackTrace(); releaseMediaRecorder(); return false; } return true; } 

then in the same package I try to play it:

  public class PlayActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play); VideoView videoView =(VideoView)findViewById(R.id.videoView); MediaController mediaController= new MediaController(this); mediaController.setAnchorView(videoView); String videoSource = "/storage/emulated/0/Android/data/com.my_pkg.camera/files/my_video.mp4"; videoView.setMediaController(mediaController); videoView.setVideoPath(videoSource); videoView.requestFocus(); videoView.start(); } } 

but I get:

Can't play video

  • Are you sure the video is on this path "/storage/emulated/0/Android/data/com.my_pkg.camera/files/my_video.mp4" ? - Vladyslav Matviienko
  • File f = new File (this.getApplicationContext (). GetFilesDir () + "/"); f.mkdirs (); - shows that there is such a file with this name - mtb
  • Is the file there? Have you checked it? handles through file manager - Vladyslav Matviienko
  • How can I get there? I don’t have root rights on my device - and if I ’m getting, I’ll lose the warranty - mtb
  • This is the path on the SD card, and not in the memory of the device, there is no need for root rights - Vladyslav Matviienko

1 answer 1

Replace String with videoSource = "/storage/emulated/0/Android/data/com.my_pkg.camera/files/my_video.mp4"; on String videoSource = getFilesDir (). getAbsolutePath () + "/my_video.mp4";