User touch quickly on MediaController. Bug only happens on Nexus 4.
Asked Answered
P

1

9

In my activity I have got a VideoView which should show a MediaController on touch. If the user touches quickly on Controller while VideoView is not following, after that user presses back button, then my app will be stuck.

setContentView(R.layout.activity_play_video_fullscreen);
videoView = (VideoView) findViewById(R.id.video_view);

urlString = getIntent().getStringExtra(EXTRA_URL);
videoView.setVideoURI(Uri.parse(urlString));
videoView.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        // video ready to play - hide progress bar
        ProgressBar pb = (ProgressBar)findViewById(R.id.progress_bar);
        pb.setVisibility(ProgressBar.INVISIBLE);
    }
});

videoView.setOnCompletionListener(new OnCompletionListener() {
    @Override
    public void onCompletion(MediaPlayer mp) {
        // video finished - terminate this activity
        AxUtils.axLog(AxUtils.eDbgLogError, AxUtils.eDbgLogGroupDialer, String.format("PlayVideoFullsreenActivity.videoView.onCompletion(): Fullscreen video playback completed.\n"));
        finish();
    }
});

// install our own error handler
videoView.setOnErrorListener(new OnErrorListener() {
    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        AxUtils.axLog(AxUtils.eDbgLogError, AxUtils.eDbgLogGroupDialer, String.format("PlayVideoFullsreenActivity.videoView.onError(): Playback failed. what=%d(%s) extra=%d(%s)\n", 
                what, what_toString(what), extra, extra_toString(extra)));
        String reason;
        if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
            reason = "Server connection lost.";
        }
        else {
            reason = extra_toString(extra);
        }
        String message = String.format("Playback Failed. %s", reason);
        Toast.makeText(PlayVideoFullscreenActivity.this.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
        finish();
        return true;
    }
});

// add playback controls
mediaController = new MediaController(this);
mediaController.setAnchorView(videoView.getRootView());
videoView.setMediaController(mediaController);
Phene answered 14/2, 2014 at 8:58 Comment(7)
Please post some codeRoyer
@Royer I was edit my postPhene
How does the app get stuck?Royer
when user scroll mediacontroller quickly, after that press back button then app stuck user cannot interactivePhene
Just free all the resources while onDestroy called.Landloper
Add some part of your log, show something irregular which need to mention?Atbara
Probably the UI gets freeze. Do the network connectivity on different thread.Wanting
O
0

In your preparedListeners, disable and enable your media controllers. It should solve your issue.

Good luck.

Offcolor answered 27/6, 2014 at 5:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.