使用SurfaceView仅在Samsung GT-I8260中渲染视频时出现问题。 IOException:准备失败:status = 0x1

时间:2015-04-21 08:34:37

标签: java android media-player android-mediaplayer surfaceview

我正在开发一个使用ViewPager的应用,每个页面都有一个视频。一切都适用于所有智能手机,但在使用Android 4.1.2的Samnsung GT-I8260中无效。

所以在这款智能手机中,当我编译它时会返回IOException:Prepare failed:status = 0x1并指向mMediaPlayer.prepare();

现在代码是下一个:

//First of all I initilize MediaPlayer and I handle the Callback method for SurfaceView
        mMediaPlayer = new MediaPlayer();
        mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                mMediaPlayer.release();
            }

            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                holder.setSizeFromLayout();
                playVideoDelay();
            }

            @Override
            public void surfaceChanged(SurfaceHolder holder,
                                       int format, int width, int height) {
            }
        });

//The app plays the first video with the next method
 private void playVideoDelay() {

        try {
            Uri path = Uri.parse("android.resource://com.casabioclimatica/raw/"+mVideoId);

            mMediaPlayer.reset();
            mMediaPlayer.setDataSource( mActivity, path);
            mMediaPlayer.setDisplay(mSurfaceView.getHolder());
            mMediaPlayer.prepare();
            if (Build.VERSION.SDK_INT >= 16)
                mMediaPlayer
                        .setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
            mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                }
            });
            // fis = new FileInputStream(new File(path.getPath()));
            //mMediaPlayer.setDataSource(fis.getFD());


        } catch (Exception e) {
            e.printStackTrace();

        }
    }
//When ViewPager changes it pages I call this method:
public void playVideoDelay(int videoId) {
        try {
            Uri path = Uri.parse("android.resource://com.casabioclimatica/raw/"+videoId);

            mMediaPlayer.reset();
            mMediaPlayer.setDataSource( mActivity, path);
            mMediaPlayer.setDisplay(mSurfaceView.getHolder());
            mMediaPlayer.prepare();
            if (Build.VERSION.SDK_INT >= 16)
                mMediaPlayer
                        .setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
            mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                }
            });



        } catch (Exception e) {
            e.printStackTrace();

        }
    }

希望有人有类似的东西,知道正确的解决方案! 谢谢!

1 个答案:

答案 0 :(得分:0)

经过大量代码更改后,我发现此智能手机存在问题,这是因为最大分辨率。在这种情况下,它有800 x 480像素,我使用1080 x 800,它太多了,Dalvik机器解释了这种情况,就像这个文件不存在或不起作用。我已经改变了文件的高宽和大小,它就像魅力一样!

因此对于任何类似的情况:请注意支持的最大屏幕分辨率,并尝试使用此大小以避免在渲染视频时出现任何奇怪的错误。

希望它有所帮助!