Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing the video in background while activity is stopped #326

Closed
abelhamilton opened this issue Mar 20, 2019 · 10 comments
Closed

Playing the video in background while activity is stopped #326

abelhamilton opened this issue Mar 20, 2019 · 10 comments
Labels

Comments

@abelhamilton
Copy link

abelhamilton commented Mar 20, 2019

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

@PierfrancescoSoffritti
Copy link
Owner

mmm this snippet looks good, you actually don't need to override onPause and onDesotry, but that's not the issue.

Are these the only places where you're using mYouTubePlayer?

I need more details to understand what's wrong.

@abelhamilton
Copy link
Author

Yes, that's the only places where I'm using mYouTubePlayer.
I'm using : implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.1'

It happens quite randomly when I quit when the youtube logo is about to appear or have just appeared and the video is still loading.

Which other details can I give you?

@PierfrancescoSoffritti
Copy link
Owner

Are you using the player in a Fragment or in an Activity?
Is there any way you can create a simple app where you replicate the issue? Only if we can replicate it we can fix it.

I never encountered this issue (but since you're saying it happens every once in a while I may just have not noticed it), you could try checking the sample app to be sure you're doing everything in the same way.

@abelhamilton
Copy link
Author

Iunderstand and I'll create a sample app later today.
I'm using it in an activity and I already checked multiple times the sample app.

@PierfrancescoSoffritti
Copy link
Owner

uhm ok. Let me know if you can replicate it, I'll be happy to look at the code!

@abelhamilton
Copy link
Author

Here is a sample app where I can reproduce it, tested on Samsung Galaxy note 3 and Android 5.0
MyApplication.zip

@abelhamilton
Copy link
Author

abelhamilton commented Mar 20, 2019

I also just tested your sample app with the basic example and I can reproduce it too.
So maybe my sample app will not be very useful after all I should have tried that first :p

@PierfrancescoSoffritti
Copy link
Owner

You're right, it seems like if you leave the app just after loadVideo is called it keeps playing. I'll fix the bug during the weekend. thank you for reporting it!

@PierfrancescoSoffritti
Copy link
Owner

Bug fixed in version 10.0.2! thank you for the help :)

@abelhamilton
Copy link
Author

No, thank YOU for your help.
I can't reproduce it anymore! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants