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

Player is playing automatically #75

Closed
didiosn opened this issue Jan 3, 2018 · 24 comments
Closed

Player is playing automatically #75

didiosn opened this issue Jan 3, 2018 · 24 comments
Labels

Comments

@didiosn
Copy link

didiosn commented Jan 3, 2018

Hi, i'm using this awesome library, but i'm facing an issue.
To reproduce the problem, play a video in the youtubeplayer. in the middle or the end, don't touch the screen, donc close the activity. Let your phone screen goes off, and after a few seconds or minute, the video start playing, and you can hear the song of the video.

Sorry for bad english.

@PierfrancescoSoffritti
Copy link
Owner

Hi, are you suspending the playback of the video in your onPause/onStop method?

@didiosn
Copy link
Author

didiosn commented Jan 3, 2018

Yes I did ... or I wait the end of the video

@PierfrancescoSoffritti
Copy link
Owner

PierfrancescoSoffritti commented Jan 3, 2018

I have just tried to replicate the issue using the sample app. Nothing happened. I have:

  1. Opened the app
  2. Waited for the video to be over
  3. Let the screen turn off
  4. Waited a couple of minutes

Nothing happened.

Are you facing the issue with the sample app or your own app?
Which version of Android are you using?

@didiosn
Copy link
Author

didiosn commented Jan 4, 2018

I'm using Android 6 for test .... i'll try on sample app.

@PierfrancescoSoffritti
Copy link
Owner

Ok, I've tried on 8.1.
Let me know if you can reproduce the issue on the sample app, thanks!

@didiosn
Copy link
Author

didiosn commented Jan 4, 2018

I had no time yet to reproduce on the sample yet, but in the buggy app, the activity is opened, load the video and start playing automatically the video. Maybe the problem is there....
I forgot to say that i code in onNewInvent too.

So now, how can i load the video without start playing it ?

@PierfrancescoSoffritti
Copy link
Owner

PierfrancescoSoffritti commented Jan 4, 2018

If you want to load a video without playing it you have to use cueVideo instead of loadVideo.
Read the documentation here.

@didiosn
Copy link
Author

didiosn commented Jan 4, 2018

OK. cueVideo seems to fix the problem. but when the screen goes off, and back on , the video restart from the begining when you start playing the video.... it should resume it, not restart

@PierfrancescoSoffritti
Copy link
Owner

PierfrancescoSoffritti commented Jan 4, 2018 via email

@PierfrancescoSoffritti
Copy link
Owner

Check the lifecycle methods of your Activity, maybe you're doing something there.

@didiosn
Copy link
Author

didiosn commented Jan 4, 2018

yeah... i checked. Ok let's try the sample app. what about the declaration of the activity in the manifest. Should i specify a launchmode ?

@PierfrancescoSoffritti
Copy link
Owner

No, as far as the player is concerned.

@didiosn
Copy link
Author

didiosn commented Jan 5, 2018

Hi, i did the sample app, but i still have the issue.
So let's me show you my code :

`
public class MainActivity extends AppCompatActivity {

private YouTubePlayerView youTubePlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    
    youTubePlayer = (YouTubePlayerView) findViewById(R.id.youtube_player_view);

    youTubePlayer.enterFullScreen();
    youTubePlayer.setVisibility(View.VISIBLE);
    youTubePlayer.initialize(new YouTubePlayerInitListener() {
        @Override
        public void onInitSuccess(final YouTubePlayer initializedYouTubePlayer) {
            initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
                @Override
                public void onReady() {
                    
                    initializedYouTubePlayer.loadVideo("asP0OPhRf2k", 0);
                }

            });
        }
    }, true);
}

}

`

@PierfrancescoSoffritti
Copy link
Owner

I have just tried the sample app: no restart issue for me.
I don't see anything problematic in your code snippet. Can't say anything about the code you have not sent me though.

You said you've been able to replicate the restarting issue in the sample app, how? send me the steps I have to follow on Android 6 in order to replicate the issue in the sample app. Otherwise I won't be able to help you.

Also I have tried the sample app on Android 6, on that version of Android the playback wasn't stopping when the Activity was being paused, because I was not calling the pause method on the YouTubePlayer. I have updated the sample app, now the playback is paused as expected.

@pralgomathic
Copy link

Things to consider****

As far as I know, playing videos in lock screen violates YouTube's Terms of Use. But as of using WebView this player can run videos even if you lock the phone screen.

@PierfrancescoSoffritti
Copy link
Owner

Yeah, it can. That's good. It's up to the developer to decide what do with it.

@pralgomathic
Copy link

Thats ok, But if I do that, google gonna ban my app? :( what do you think ?

@PierfrancescoSoffritti
Copy link
Owner

Yes, if you do that and publish the app on the Play Store they're going to remove it, sooner or later!

@pralgomathic
Copy link

what about If I publish app with removing YouTube logo from the player and using my own controls as the way you did in here .

@PierfrancescoSoffritti
Copy link
Owner

No, the player is still using YouTube, therefore you have to respect their terms of service.

@PierfrancescoSoffritti
Copy link
Owner

I suggest you just pause the video when the player is not visible

@pralgomathic
Copy link

I am trying to design the player with putting all controls outside of the playerview. Where Should I put the logo then ? any suggestion ?

@PierfrancescoSoffritti
Copy link
Owner

That's outside the scope of this issue. If you want help not related to this library feel free to send me an email, I'll be happy to offer suggestions. Good luck :)

@pralgomathic
Copy link

oh! sorry for that. Check the mail please :)

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

3 participants