错误surfaceTexture不能为null

时间:2017-03-05 01:40:25

标签: java android

我尝试播放一些视频。但是一旦我重现第一个视频就会出错:

  

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不会为空?

0 个答案:

没有答案