2

I want to create a media player to stream video from resource, which is normally available only from web browser and hence isn't too convenient for mobile. I've little experience in Android development and therefore first issue has puzzled me. So, what I've done:

  1. Added <uses-permission android:name="android.permission.INTERNET" /> to the manifest
  2. Created a VideoView in my only activity
  3. Ran following code:
        VideoView videoView = (VideoView)findViewById(R.id.videoView);
        MediaController mediaController= new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri uri = Uri.parse("http://home/video.mp4");
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();

when I run it in the Android emulator on videoView.setVideoURI(uri) I'm getting an error:

java.io.FileNotFoundException: No content provider: http://home/video.mp4 At the same time same URL opens in Chrome browser in same emulator without issues.

I've digged a little and found out the error occurs in MediaPlayer.attemptDataSource because it uses default ContentResolver, which accepts only "content://" scheme.

I couldn't find any mention of setting content resolver when creating a media player on the web. Do I need to do it differently?

Ralfeus
  • 845
  • 9
  • 31
  • https://stackoverflow.com/a/40435356/11982611 this link should help for this trouble. By the way I recommend to use media player or exo player for this. – Eren Tüfekçi May 13 '20 at 19:00
  • Thank you for the advise. However setVideoPath is just a wrapper around setVideoURI. I tried that as well and it didn't help. – Ralfeus May 13 '20 at 20:07
  • is `http://home` a hostname for a local adresse on your computer? – Biscuit May 13 '20 at 20:14
  • It's a host name of another computer in my local network – Ralfeus May 13 '20 at 20:14
  • Is `android:usesCleartextTraffic="true"` in your manifest? – Biscuit May 13 '20 at 20:19
  • Yes, it's set.. – Ralfeus May 13 '20 at 20:25
  • Ok, I've moved a little with a problem. It seems the video is played on a real device but fails on an emulator. And FileNotFoundException is thrown in any case. However the issue is indeed with opening file because the web server logs show request when I run the application on physical device but nothing is logged when I run the app on the emulator. – Ralfeus May 14 '20 at 08:01

0 Answers0