Android无法创建媒体播放器

时间:2015-11-09 06:15:49

标签: android android-mediaplayer android-textureview

我有一个mp4视频,我尝试在TextureView中播放我的视频。

我有一个问题。在Nexus或HTC中我没有问题,但在某些华为设备中我有这个消息

Unable To create Media player

这是我的来源

 private void playVideoAnimation()
{
    textureView.setVisibility(View.VISIBLE);
    mMediaPlayer = new MediaPlayer();

    textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
            Surface surface = new Surface(surfaceTexture);

            try {
                Log.e("FILE_NAME", FILE_NAME);
                AssetFileDescriptor afd = getAssets().openFd(FILE_NAME);

                mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
                mMediaPlayer.setSurface(surface);

                mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mediaPlayer) {

                        if (mediaPlayer.isPlaying()) {

                        }
                        mediaPlayer.start();

                    }
                });
                mMediaPlayer.prepareAsync();

            } 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());
            }
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {

        }

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {


            return false;
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surface) {

        }
    });

    mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {

            Log.e("FILE_NAME", "Finished");

        }

    });



}

正如我所说,我可以在Nexus和HTC设备上播放我的视频,但昨天我在华为运行我的应用程序,我收到此错误消息。

我如何检查设备是否可以播放视频?

如果有人知道解决方案,请帮助我

0 个答案:

没有答案