我尝试播放一些视频。但是一旦我重现第一个视频就会出错:
java.lang.RuntimeException:无法启动活动 ComponentInfo {cpm.example.advplayer / com.example.advplayer.ui.MainActivity}: java.lang.IllegalArgumentException:surfaceTexture不能为null
我在playerSetup()
方法中写道:
public void playerSetup(Video video) {
try {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(Application.video_path + video.getName());
mMediaPlayer.setSurface(new Surface(savedSurfaceTexture));
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
adjustAspectRatio(mMediaPlayer.getVideoWidth(), mMediaPlayer.getVideoHeight());
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
和
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
savedSurfaceTexture = surfaceTexture;
}
在onSurfaceTextureAvailable()
覆盖方法
如何制作以便每次都可以播放视频而TextureVuew
不会为空?