假设我们有以下内容(来自 Android ApiDemos):
<?xml version="1.0" encoding="utf-8"?>
<SurfaceView android:id="@+id/surface"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</SurfaceView>
MediaPlayer使用SurfaceView后,调用了它的release(),SurfaceView可以复用吗?我试图创建一个新的MediaPlayer实例来重用SurfaceView,但是在setDisplay()处出现以下错误:java.lang.IllegalArgumentException: The surface has been released
代码如下:
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
mMediaPlayer = new MediaPlayer();
MediaPlayer.setDataSource(url);
mMediaPlayer.setDisplay(holder);