Question

Hi I have checked lot in the google can't get the correct answer my problem is

I want to show the video in surface view using media player I am succeed using video which is in SD card but when I try something in Server I can't. Following is my code.

mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder); 
mediaPlayer.setDataSource(my url here);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
     public void onPrepared(MediaPlayer mp) {
         mp.start();
     }
});
Was it helpful?

Solution

I'm working with this to play video:

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"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top