Pergunta

I have to play video from php server in android by using url. So I used the below code. But its not working. I don't know the mistake which I had done.

VideoView video = (VideoView)findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
String Video="http://xxx/android/deepcut.mp4";
video.setMediaController(mediaController);
video.setVideoURI(Uri.parse(Video));
video.start();

Can anyone help me ?

Foi útil?

Solução

-38 refers to ENOSYS error code from errno.h (see this explanation https://stackoverflow.com/a/15206308/768935)

You seem to try to start the playing before the preparation is complete. Use the setOnPreparedListener() method to set a preparation listener and call the start() method only after the preparation is complete.

mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
  public void onPrepared(MediaPlayer mp) {
      mp.start();
  }
});
mediaPlayer.prepareAsync();

And remove the current video.start() invocation from the code.

Took from here

Credits goes to him

Outras dicas

try this:

MainActivity.java:

String urlStr = "http://videos.com/link/to/video.mp4";
Uri uri = Uri.parse(urlStr);

VideoView vv = (VideoView) findViewById(R.id.videoView1);
vv.setOnErrorListener(new OnErrorListener() {
    @Override
    public boolean onError(MediaPlayer arg0, int arg1, int arg2) {return false;}
});
try {vv.setVideoURI(uri);} catch (Exception e) {}
try {vv.start();} catch (Exception e) {}
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
        mp.setOnCompletionListener(null);
    }
});

add these permissions in AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Your code is essentially correct. The only permission needed to play a video from the internet is internet permission. You can do this by adding:

<uses-permission android:name="android.permission.INTERNET"/>

in your manifest (inside the section)

What's also probable is that you are trying to play a video that is not supported by your device, e.g. playing a main/extended/high profile, or a level 5 AVC video, or even HEVC. You can run avprobe/ffprobe on your file to get the profile and codec info for it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top