Android:媒体播放器在几秒钟后停止

时间:2016-08-11 13:58:05

标签: android media-player

我将此代码用于流视频

但是在5-6秒后,玩家停止了

如果我使用mp4格式,正确

但是使用流URL会在秒后停止

public static SurfaceView    videoSurface = null;
public SurfaceHolder         videoHolder  = null;
public static MediaPlayer    mediaPlayer;

new Thread(new Runnable() {

    @Override
    public void run() {
        mediaPlayer = null;
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);
        try {
            mediaPlayer.setDisplay(videoHolder);
            String file = "http://test.com/file.m3u8";
            mediaPlayer.setDataSource(file);
            mediaPlayer.prepare();  
            mediaPlayer.setOnPreparedListener((OnPreparedListener) this);
            mediaPlayer.prepareAsync();
         }
         catch (Exception e) {
             e.printStackTrace();
         }
         mediaPlayer.setLooping(true);
         mediaPlayer.start();
     }
}).start();

如何解决?

  

Logcat:

08-11 18:42:21.370: V/MediaPlayer(6060): callback application
08-11 18:42:21.370: V/MediaPlayer(6060): back from callback
08-11 18:42:21.370: I/MediaPlayer(6060): Info (702,0)
08-11 18:42:21.370: I/MediaPlayer(6060): Info (3,0)
08-11 18:42:46.835: V/MediaPlayer(6060): message received msg=200, ext1=701, ext2=0
08-11 18:42:46.835: W/MediaPlayer(6060): info/warning (701, 0)
08-11 18:42:46.835: V/MediaPlayer(6060): callback application
08-11 18:42:46.835: V/MediaPlayer(6060): back from callback
08-11 18:42:46.840: I/MediaPlayer(6060): Info (701,0)
08-11 18:42:46.940: V/MediaPlayer(6060): message received msg=2, ext1=0, ext2=0
08-11 18:42:46.940: V/MediaPlayer(6060): playback complete
08-11 18:42:46.940: V/MediaPlayer(6060): callback application
08-11 18:42:46.940: V/MediaPlayer(6060): back from callback

2 个答案:

答案 0 :(得分:0)

由于它适用于本地文件,因此IMO是实际播放列表http://test.com/file.m3u8的唯一原因。该文件或流媒体服务器设置可能存在一些问题。

答案 1 :(得分:0)

问题可能在于文件格式,Android媒体播放器不支持此文件格式,请检查this