0

Please find below xml

<VideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />

Java Code:

  String url = "android.resource://com.example.androidtutorial/" + R.raw.instructions;
  videoView.setVideoURI(Uri.parse(url));
  videoView.start();

Error is shown in Logcat:

2019-10-20 10:51:16.708 5063-5063/? E/androidtutoria: Unknown bits set in runtime_flags: 0x8000
2019-10-20 10:51:22.825 5063-5080/com.example.androidtutorial E/MediaPlayerNative: error (1, -2147483648)
2019-10-20 10:51:23.178 5063-5063/com.example.androidtutorial E/MediaPlayer: Error (1,-2147483648)

I saw many samples on the internet that uses the same code, but in my case, it is not working.

Jitesh Mohite
  • 31,138
  • 12
  • 157
  • 147

1 Answers1

0

I advice you to user a WebView instead of video view.

that will work better.

But for your answer

1.check your connection

2.check your permissions

3.check Url that you build with Debug

4.put start method in try catch

Now its seems issue in this line:

videoView.setVideoURI(Uri.parse(url));

uri means a file path in your device not a url, check it and try again.

u can update me in comments

Edited: use this method:

public Uri getRawUri(String filename) {
    return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + 
File.pathSeparator + File.separator + getPackageName() + "/raw/" + 
filename);
}

next solution: use Uri.fromFile instead of Uri.parse

And

Use this 2 methods:

video.setVideoURI(URI);
video.setMediaController(new MediaController(this));
video.requestFocus();
video.start();

Try this in your onCreate() method:

Uri URI = getRawUri(instructions);
MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(video)

video.setVideoURI(URI);
video.setMediaController(mediaController);
video.requestFocus();
video.start();
alireza daryani
  • 787
  • 5
  • 16