question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Playing the video in background while activity is stopped

See original GitHub issue

Hello, thanks again for this wonderful library!

Maybe I’m missing something but the player continues playing in the background when I press the home button or open another activity. It happens sometimes only when the video is not loaded yet even when mYouTubePlayer.pause(); is called in the onPause method.

Here is what I do :

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        ButterKnife.bind(this);

        mVideo = (Video) getIntent().getSerializableExtra(Constant.INTENT_OBJECT);
        mVideoActivity = (VideoAct) getIntent().getSerializableExtra(Constant.INTENT_ACTIVITY);

        initYoutubePlayer();
    }

private void initYoutubePlayer() {
        getLifecycle().addObserver(youtubePlayerView);
        youtubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
            @Override
            public void onReady(@NonNull YouTubePlayer youTubePlayer) {
                mYouTubePlayer = youTubePlayer;
                int startTime = 0;
                if (mVideoActivity != null) {
                    startTime = mVideoActivity.timeCode;
                }
                YouTubePlayerUtils.loadOrCueVideo(mYouTubePlayer, getLifecycle(), videoKey, startTime);
            }
        });
}

@Override
public void onPause() {
    super.onPause();
    if (mYouTubePlayer != null) {
       mYouTubePlayer.pause();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    youtubePlayerView.release();
}

Thanks in advance

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
abelhamiltoncommented, Mar 24, 2019

No, thank YOU for your help. I can’t reproduce it anymore! 😃

0reactions
PierfrancescoSoffritticommented, Mar 24, 2019

Bug fixed in version 10.0.2! thank you for the help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - How to stop playing video when Parent Activity is in ...
I have recently tried to use ExoPlayer from google in my android project. Exoplayer is keep playing video even I have call all...
Read more >
Restrictions on starting activities from the background
Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background....
Read more >
Can't update Live Activity from ap… | Apple Developer Forums
Can't update Live Activity from app with ActivityKit when app is running in the background with background audio playing.
Read more >
Turn on background data - Google Play Help
Turn on background data · Open your device's Settings app . · Tap Network & internet. · Tap Data usage and then ·...
Read more >
Windows background apps and your privacy - Microsoft Support
Stop an app from running in the background ... If you don't want to get notifications or updates for an app when you're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found