0

我试图在我的纹理视图中放置一个媒体控制器,但我总是有一个错误说

E/MediaPlayer﹕ Should have subtitle controller already set

这是我的代码

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.texture_video);

    textureView = (TextureView) findViewById(R.id.textureView);
    listView = (ListView) findViewById(R.id.list);

  .
  .
  .

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, android.R.id.text1, values);


    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {

            if (position == 0) {
                onDestroy();
                FILE_NAME = "test1.mp4";
                textureView.setSurfaceTextureListener(VideoAssetActivity.this);
                onSurfaceTextureAvailable(textureView.getSurfaceTexture(), view.getWidth(), view.getHeight());
            } else if (position == 1) {
                onDestroy();
                FILE_NAME = "test2.mp4";
                textureView.setSurfaceTextureListener(VideoAssetActivity.this);
                onSurfaceTextureAvailable(textureView.getSurfaceTexture(), view.getWidth(), view.getHeight());
            } else if (position == 2) {
                onDestroy();
                FILE_NAME = "test3.mp4";
                textureView.setSurfaceTextureListener(VideoAssetActivity.this);
                onSurfaceTextureAvailable(textureView.getSurfaceTexture(), view.getWidth(), view.getHeight());
            } else if (position == 3) {
                onDestroy();
                FILE_NAME = "test4.mp4";
                textureView.setSurfaceTextureListener(VideoAssetActivity.this);
                onSurfaceTextureAvailable(textureView.getSurfaceTexture(), view.getWidth(), view.getHeight());
            }
        }

    });
    textureView.setSurfaceTextureListener(this);

}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mMediaPlayer != null) {
        mMediaPlayer.stop();
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
    Surface surface = new Surface(surfaceTexture);

    try {
        AssetFileDescriptor afd = getAssets().openFd(FILE_NAME);
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        mMediaPlayer.setSurface(surface);
        mMediaPlayer.setLooping(true);
        mMediaPlayer.prepareAsync();

        onSurfaceTextureUpdated(surfaceTexture);

        mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // set up media controller
                videoController = new MediaController(VideoAssetActivity.this);
                videoController.setAnchorView(textureView);
                videoController.setPadding(0, 0, 0, 0);

                    mediaPlayer.start();

            }
        });

    } catch (IllegalArgumentException e) {
        Log.d(TAG, e.getMessage());
    } catch (SecurityException e) {
        Log.d(TAG, e.getMessage());
    } catch (IllegalStateException e) {
        Log.d(TAG, e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }


}

我的问题是我已经设置了控制器,但即使我播放其他 mp4 也不会显示。我已经搜索了解决方案,但我只看到音频文件。谁能帮我?非常感谢您..

4

1 回答 1

4
  • 实施MediaController.MediaPlayerControl
  • 覆盖所需的功能
  • 通过此代码显示控制器:

    MediaController videoController = new MediaController(getActivity());
    videoController.setMediaPlayer(this);//your activity which implemented MediaPlayerControl
    videoController.setAnchorView(mTextureView);
    videoController.setEnabled(true);
    videoController.show();
    

    玩得开心!

于 2015-06-01T04:19:36.533 回答