문제

I have got an error concerning MediaPlayer in combination with a surfaceview:

I am playing a video in a surfaceview by Streaming it from the Internet as follows:

    mPreview = (SurfaceView) findViewById(R.id.surface);
    videoFL = (FrameLayout) findViewById(R.id.videoFL);
    SurfaceHolder holder = mPreview.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

Lateron I try to attach my first MediaPlayer to it:

    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setDataSource(videos.get(position));
    mediaPlayer.prepareAsync();
    mediaPlayer.setOnBufferingUpdateListener(this);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setOnVideoSizeChangedListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDisplay(holder);

While Streaming the first video I am already buffering the second one to save my users time. To attach the second already prepared MediaPlayer instance to my SurfaceView I do the following an release the old one:

        mediaPlayer.release();
        mediaPlayer = null;
        ....
        mediaPlayer2.setDisplay(holder);

On ICS and Jelly Bean this solution works fine but on Gingerbread it doesn't work as planned. The video is being played but not displayed (black screen and only once a picture is shown somewhere within the video) which I recognized via:

mediaPlayer2.getCurrentPosition();

where I always get the correct position on my SeekBar. I have tried it on an HTC Wildfire S.

Has anyone possibly a guess why this error could happen on Gingerbread?

With regards,

tsemann

도움이 되었습니까?

해결책

I did reduce my version now to one MediaPlayer because as I stated in my question it is true that some 2.x devices do not have the capability to use a second MediaPlayer instance in the same Activity. So I always reinstantiate my MediaPlayer by calling the prepare()-method for the upcoming video.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top