Audio keeps playing, while video stops after releasing Exoplayer

156
February 07, 2019, at 07:00 AM

I have an Exoplayer in a fragment, and im trying to save the state of the player after rotation. I am using a StepView and feeding the player with different URIs after each step click.

Right now when i rotate the screen during a video, the audio keeps playing until the end of its duration but video stops.

public void initializePlayer(Uri uri) {
    if (uri == null) {
        exoPlayerView.setVisibility(View.GONE);
    } else {
        defaultBandwidthMeter = new DefaultBandwidthMeter();
        trackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
        trackSelector = new DefaultTrackSelector(trackSelectionFactory);
        exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector);
        exoPlayerView.setPlayer(exoPlayer);
        exoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH);
        dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "bakingapp"), defaultBandwidthMeter);
        mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(stepList.get(savedStep).getStepVideoUrl()));
        exoPlayer.prepare(mediaSource);
        if (playbackPosition != C.TIME_UNSET) {
            exoPlayer.seekTo(playbackPosition);
        }
        exoPlayer.setPlayWhenReady(playWhenReady);
    }
}

@Override
public void onResume() {
    super.onResume();
    videoUri= Uri.parse(stepList.get(savedStep).getStepVideoUrl());
    stepView.go(savedStep, true);
    if ((Util.SDK_INT <= 23 || exoPlayer == null)) {
        initializePlayer(videoUri);
    }
 @Override
public void onPause() {
    super.onPause();
        if (Util.SDK_INT <= 23) {
            releasePlayer();
        }
}
private void releasePlayer() {
    if (exoPlayer != null) {
        playWhenReady = exoPlayer.getPlayWhenReady();
        playbackPosition = exoPlayer.getCurrentPosition();
        exoPlayer.stop();
        exoPlayer.release();
       exoPlayer = null;
    }
}
Rent Charter Buses Company
READ ALSO
How do I update a RecyclerView on sorting the data?

How do I update a RecyclerView on sorting the data?

My database (Firestore) stores Charts, created by Users

243
Cannot download files on Android Web View (cordova)

Cannot download files on Android Web View (cordova)

I have recently wrapped my Angular 7 app to Cordova Android Web View, and everything work except my download function which simply downloads a text file, it is working on the Angulare version on the browser but not on Android Web View, the function uses fileSaverjs...

166
How can i create an already set start time and end time with ID values and connect it into real time?

How can i create an already set start time and end time with ID values and connect it into real time?

I want to be able to change ID values when time passes my end_time value

103
MySQL INSERT inserting BIT to 1 instead of 0

MySQL INSERT inserting BIT to 1 instead of 0

I have the following query which should insert a 0 but instead inserts 1It is executed with prepared statements in PHP:

116