Search code examples
javaandroidmedia-playerandroid-mediaplayersurfaceview

Problems rendering video only in Samnsung GT-I8260 using SurfaceView. IOException: Prepare failed.: status=0x1


I'm developing an app that uses a ViewPager with one video in each page. Everything works well in every smartphone but it doesn't work in Samnsung GT-I8260 with Android 4.1.2

So in this smartphone, when I compile it returns IOException: Prepare failed.: status=0x1 and it points to mMediaPlayer.prepare();

Now the code is the next:

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

        }
    }

Hope somebody has had something similar and knows the proper solution! Thanks!


Solution

  • After a lot of code changes,I have found the problem in this smartphone, this is because of the maximum resolution. In this case it has 800 x 480 px and I was using 1080 x 800, it was too much and the Dalvik machine interprets that case like this file doesn't exist or doesn't work. I have changed the high and width size of the file and it works like charm!

    So for any similar case: Pay attention to your maximum screen supported resolution and try to use this size to avoid any strange error when you render a video.

    Hope it helps!