3

I'm working on an application that records video from the camera and then moves to Activity with video preview. Basically, it works fine, but if user records video, moves to video preview screen and returns back to camera multiple times in a row, VideoView eventually returns an error

(E/MediaPlayer: error (1, -19))

and can't play video. After that, this error repeats for every recorded video until I kill the app and start it again. Recorded video is valid, MediaMetadataRetriever can parse it and I can play it via other video player apps.

After searching for a possible solution I checked whether the problem in unreleased MediaPlayer. But moving VideoView.suspend(), that releases MediaPlayer, in onStop() of Activity or in onError() of VideoView hasn't helped.

Is there any idea why this error occurs how to avoid it and why it repeats until I kill the app?

This issue reproduces on Samsung Galaxy S8 (Android 7.0)

compileSdkVersion 25
buildToolsVersion 25.0.2
targetSdkVersion  25

Here is simplified code of VideoView initialization

public class ErrorVideoViewActivity extends AppCompatActivity {

    private static final String EXTRA_URI = "EXTRA_URI";

    private VideoView mVideoView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trimmer);
        mVideoView = (VideoView) findViewById(R.id.video_view);
        mVideoView.setOnPreparedListener(mp -> {
            //Do some UI stuff
        });
        mVideoView.setOnClickListener(view -> {
            if (mVideoView.isPlaying()) {
                mVideoView.pause();
            } else {
                mVideoView.start();
            }
        });
        mVideoView.setOnCompletionListener(mp -> mp.seekTo(0));
        final Intent intent = getIntent();
        if (!intent.hasExtra(EXTRA_URI)) {
            throw new IllegalArgumentException();
        }

        mVideoView.setVideoURI(intent.getParcelableExtra(EXTRA_URI));
    }

    @Override
    protected void onStop() {
        super.onStop();
        mVideoView.suspend();
    }
}

0 Answers0