1

I'm trying to play a video which is loaded in the res/raw folder. I've put it in res/raw/ but I'getting "MediaPlayer: Couldn't open" when I click on the button to play the video.

I think the issue is with how I am referencing the video, or there may be something I need to change in a manifest file. is there something obvious that I'm doing wrong?

The code is the following:

    public void playVideo(View v) {
    MediaController m = new MediaController(this);
    vid.setMediaController(m);

    //String path = "android.resource://" + getPackageName() + "+R.raw.hellologanhd";
    String path = "/Users/xxxx/AndroidStudioProjects/HelloLogan/app/src/main/res/raw/hellologanhd";
    System.out.println("path = "+ path);
    Log.d("State", "Video Path: "+ path);
    Uri u = Uri.parse(path);

    vid.setVideoURI(u);

    vid.start();

}

The file is located below in the src

location of mp4

The logs are showing the following, I've use logging to check the the variable is correct, I've swapped around the variable also, to check my referencing to it is correct.

2020-08-25 09:43:30.700 30392-30392/com.example.hellologan D/State: Video Path: /Users/xxxx/AndroidStudioProjects/HelloLogan/app/src/main/res/raw/hellologanhd 2020-08-25 09:43:30.710 30392-30392/com.example.hellologan W/MediaPlayer: Couldn't open /Users/xxxx/AndroidStudioProjects/HelloLogan/app/src/main/res/raw/hellologanhd: java.io.FileNotFoundException: No content provider: /Users/xxxx/AndroidStudioProjects/HelloLogan/app/src/main/res/raw/hellologanhd 2020-08-25 09:43:30.711 30392-30392/com.example.hellologan W/VideoView: Unable to open content: /Users/xxxx/AndroidStudioProjects/HelloLogan/app/src/main/res/raw/hellologanhd java.io.IOException: setDataSource failed.

This is what I am using as a guide: https://technobyte.org/using-mediaplayer-play-pause-stop-audio-file-android/

pat
  • 95
  • 1
  • 1
  • 10
  • checkout this [answer](https://stackoverflow.com/questions/24276451/android-mediaplayer-play-audio-resource-in-raw-based-on-uri) – liad horovitz Aug 25 '20 at 09:11
  • 1
    Yes. You use a path of your windows machine. Of course an app on your Android device cannot use that path. Not at home and not if you are with phone in town. – blackapps Aug 25 '20 at 09:11
  • 1
    have you tried `MediaPlayer mp = MediaPlayer.create(this, R.raw.sonar_slow);`. Refer : https://stackoverflow.com/questions/18254870/play-a-sound-from-res-raw – Akshay Aug 25 '20 at 09:15

0 Answers0