没有日志,有两个建议:
>尝试实现SurfaceHolder.Callback.surfaceCreated().
>尝试使用接受SurfaceHolder的MediaPlayer.create()
细节(1)
调用start()时,可能还没有创建表面.只有在创建表面后才应使用MediaPlayer.setDisplay()和MediaPlayer.start().为此,您应该添加overrideSurfaceHolder.Callback.surfaceCreated()`.例如,您的代码可能如下所示.
public class MediaPlayerActivity extends Activity implements SurfaceHolder.Callback {
MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.video_player);
SurfaceView v = (SurfaceView) findViewById(R.id.surface_video);
SurfaceHolder holder = v.getHolder();
holder.setFixedSize(400,300);
holder.addCallback(this).
mp = MediaPlayer.create(this, Uri.parse("http://stream-url.com/playlist.m3u8"));
@Override
public void surfaceCreated(SurfaceHolder holder) {
mp.setDisplay(holder);
try {
mp.start();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
}
细节(2)
似乎有其他MediaPlayer.create()接受SurfaceHolder作为参数之一 – 您可以尝试它:http://developer.android.com/reference/android/media/MediaPlayer.html#create(android.content. Context,android.net.Uri,android.view.SurfaceHolder)