Alright, so to play the videos using the Standalone Player, we used it to create videoIntent and create
playlistIntent methods to get an Intent, that we then used to start an activity in Google's YouTube Player app.
Now if we go back and check the documentation again for the YouTubeStandalonePlayer, just scroll down and
have a look, there's an overloaded version of the createVideoIntent.
You can see this one here, it's actually got three additional parameters.
Now one is an integer called timeMillis, which is how far into the video, playback should start.
We want to start at the beginning so we're going to use 0 for that one.
Now the next one is the one we want,
a Boolean called autoplay that starts playing immediately.
So we're going to set that one to True, boolean autoplay as you can see there. I'll just scroll over so we can
that a little bit better.
Now the next one, the final parameter's interesting.
It's a boolean called like lightboxMode, you see this up here,
and that's set to False to play the video in full screen mode.
We're going to use False for that here, but we'll experiment with it later to see what differences that
makes setting that.
So the first thing we need to do is go back to our code in Android Studio,
and go back to our StandaloneActivity, and this is obviously the code where we created our Intent. Now at the moment you
can see that we've got our YouTubeStandalonePlayer.createPlaylistIntent, and then on the previous
line, on line 40, we've got YouTubeStandalonePlayer.createVideoIntent, and at the moment we haven't got all those additional
arguments.
So if you go ahead and make those changes now that we talked about, so firstly I'm going to come up after the
YouTube video id comma space 0 comma space true.
comma space false.
That's those three arguments that we just talked about, and the next thing we need to do is create the
PlaylistIntent, and just going back to the documentation again for the PlaylistIntent.
You can see up here, we've got similar parameters for the PlaylistIntent.
We've got timeMillis, boolean autoplay and boolean lightboxMode again.
But there's also this additional parameter here,
the fourth one, which comes before the other three:
the start index, and that's used to start playing a specific video in the playlist, but
we want to start with the first one so we're going to be using index zero there for that.
Alright so let's go back to the code. So this is now for the PlaylistIntent,
the second bit of code, we'll create PlaylistIntent. So after the Playlist we want to add 0 because we're
starting from the first video, 0 again, true,
and then for lightboxMode this time we're going to select true and see what that looks like.
So that's the four arguments now for the createPlaylistIntent.
So those should be the only two changes we need to make, and the videos we start from the Standalone menu
should now start playing automatically.
So we're going to run the program to see, so let's go back to our emulator
first though. we're going to put it back in landscape mode.
Alright, so I'm going to play the video, and go back and check it out.
So first we need to go into the Standalone submenu.
We're going to click on play video, and you can see that's now working. The Standalone submenu options for
playing the video works, and the video started playing automatically.
So I'll pause that, and we'll go back, click on Play Playlist, and you can see the video's also autoplaying there
as well. So I'll pause that as well. Alright, now the Playlist videos do look a little bit different though,
when I rotate the device into portrait. You can really see the difference, so
basically instead of running full screen, the video is going to run in a dialogue on top of our activity.
It's an interesting effect and it's nice to know that you can do that if you want to, so let's go back and see
how that works. So what we'll do is we'll go back to portrait mode,
and you can see that's overlaying there now. We'll play this, and just to see how that works,
and if I pause the video again and go back, click on Playlist, you can see how this lightboxMode effectively
looks like a video that is for all intent purposes
is playing over the top of our activity. It's an
interesting effect there, but obviously it's still working in portrait mode which is good.
So what's happening here is that Google had prevented the activities in their player from being destroyed
when the orientation changes.
And as I mentioned we will be seeing how to do that ourselves.
So as a result of doing that, Google have also had to write code to cope with the change of orientation,
and resize their layout themselves instead of relying on the default behavior.
Now when the lightboxMode isn't used, the activity makes no attempt to handle the resolution change,
which is why we get a landscape screen on the side. But in lightboxMode, Google have to deal with the resizing
themselves, so it can be done if you decide to do that but it's quite a bit of extra coding.
Alright, so that's the solution, or our solution to the challenge.
Congratulations if you managed to complete it.
So I'll finish the video here, and in the next one, we're going to have a look at that request code that we
saw a few videos back. So I'll see you in the next video.