Search code examples
androidvideoandroid-videoviewmp4

VideoView can not play video


final VideoView videoView = (VideoView) findViewById(R.id.surface_view);
videoView.setVideoPath("/edited_For Render - 1280x720.mp4");
videoView.start();

i'm trying to play a video in my app, but when i run it on my nexus 4 it says that the video can not be played. the video is placed in the res folder of the project in android-studio and it's an mp4 with H.264 codec.


Solution

  • i solved it.

    the problem was the video path. it has to be

    videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.trailer);
    

    (i also had to rename the file to trailer.mp4 because android can't handle spaces in filenames and i moved it to the raw folder)