1 00:00:05,180 --> 00:00:11,590 Alright, so to play the videos using the Standalone Player, we used it to create videoIntent and create 2 00:00:11,590 --> 00:00:19,100 playlistIntent methods to get an Intent, that we then used to start an activity in Google's YouTube Player app. 3 00:00:19,100 --> 00:00:24,010 Now if we go back and check the documentation again for the YouTubeStandalonePlayer, just scroll down and 4 00:00:24,010 --> 00:00:28,270 have a look, there's an overloaded version of the createVideoIntent. 5 00:00:28,270 --> 00:00:32,310 You can see this one here, it's actually got three additional parameters. 6 00:00:32,310 --> 00:00:38,310 Now one is an integer called timeMillis, which is how far into the video, playback should start. 7 00:00:38,310 --> 00:00:41,760 We want to start at the beginning so we're going to use 0 for that one. 8 00:00:41,760 --> 00:00:43,650 Now the next one is the one we want, 9 00:00:43,650 --> 00:00:47,040 a Boolean called autoplay that starts playing immediately. 10 00:00:47,040 --> 00:00:50,310 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 11 00:00:50,310 --> 00:00:53,390 that a little bit better. 12 00:00:53,390 --> 00:00:55,820 Now the next one, the final parameter's interesting. 13 00:00:55,820 --> 00:00:59,560 It's a boolean called like lightboxMode, you see this up here, 14 00:00:59,560 --> 00:01:03,190 and that's set to False to play the video in full screen mode. 15 00:01:03,190 --> 00:01:08,260 We're going to use False for that here, but we'll experiment with it later to see what differences that 16 00:01:08,260 --> 00:01:09,670 makes setting that. 17 00:01:09,670 --> 00:01:15,940 So the first thing we need to do is go back to our code in Android Studio, 18 00:01:15,940 --> 00:01:23,890 and go back to our StandaloneActivity, and this is obviously the code where we created our Intent. Now at the moment you 19 00:01:23,890 --> 00:01:29,260 can see that we've got our YouTubeStandalonePlayer.createPlaylistIntent, and then on the previous 20 00:01:29,260 --> 00:01:34,900 line, on line 40, we've got YouTubeStandalonePlayer.createVideoIntent, and at the moment we haven't got all those additional 21 00:01:34,900 --> 00:01:37,570 arguments. 22 00:01:37,570 --> 00:01:41,610 So if you go ahead and make those changes now that we talked about, so firstly I'm going to come up after the 23 00:01:41,610 --> 00:01:48,310 YouTube video id comma space 0 comma space true. 24 00:01:48,310 --> 00:01:51,280 comma space false. 25 00:01:51,280 --> 00:01:56,420 That's those three arguments that we just talked about, and the next thing we need to do is create the 26 00:01:56,420 --> 00:02:03,320 PlaylistIntent, and just going back to the documentation again for the PlaylistIntent. 27 00:02:03,320 --> 00:02:07,490 You can see up here, we've got similar parameters for the PlaylistIntent. 28 00:02:07,490 --> 00:02:12,650 We've got timeMillis, boolean autoplay and boolean lightboxMode again. 29 00:02:12,650 --> 00:02:15,260 But there's also this additional parameter here, 30 00:02:15,260 --> 00:02:18,530 the fourth one, which comes before the other three: 31 00:02:18,530 --> 00:02:25,310 the start index, and that's used to start playing a specific video in the playlist, but 32 00:02:25,310 --> 00:02:29,540 we want to start with the first one so we're going to be using index zero there for that. 33 00:02:29,540 --> 00:02:32,810 Alright so let's go back to the code. So this is now for the PlaylistIntent, 34 00:02:32,810 --> 00:02:38,710 the second bit of code, we'll create PlaylistIntent. So after the Playlist we want to add 0 because we're 35 00:02:38,710 --> 00:02:43,900 starting from the first video, 0 again, true, 36 00:02:43,900 --> 00:02:48,350 and then for lightboxMode this time we're going to select true and see what that looks like. 37 00:02:48,350 --> 00:02:52,640 So that's the four arguments now for the createPlaylistIntent. 38 00:02:52,640 --> 00:02:58,340 So those should be the only two changes we need to make, and the videos we start from the Standalone menu 39 00:02:58,340 --> 00:03:00,680 should now start playing automatically. 40 00:03:00,680 --> 00:03:04,730 So we're going to run the program to see, so let's go back to our emulator 41 00:03:04,730 --> 00:03:13,160 first though. we're going to put it back in landscape mode. 42 00:03:13,160 --> 00:03:17,350 Alright, so I'm going to play the video, and go back and check it out. 43 00:03:17,350 --> 00:03:20,080 So first we need to go into the Standalone submenu. 44 00:03:20,080 --> 00:03:25,180 We're going to click on play video, and you can see that's now working. The Standalone submenu options for 45 00:03:25,180 --> 00:03:28,660 playing the video works, and the video started playing automatically. 46 00:03:28,660 --> 00:03:35,690 So I'll pause that, and we'll go back, click on Play Playlist, and you can see the video's also autoplaying there 47 00:03:35,690 --> 00:03:41,090 as well. So I'll pause that as well. Alright, now the Playlist videos do look a little bit different though, 48 00:03:41,090 --> 00:03:45,140 when I rotate the device into portrait. You can really see the difference, so 49 00:03:45,140 --> 00:03:49,520 basically instead of running full screen, the video is going to run in a dialogue on top of our activity. 50 00:03:49,520 --> 00:03:53,420 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 51 00:03:53,420 --> 00:03:59,030 how that works. So what we'll do is we'll go back to portrait mode, 52 00:03:59,030 --> 00:04:03,940 and you can see that's overlaying there now. We'll play this, and just to see how that works, 53 00:04:03,940 --> 00:04:10,020 and if I pause the video again and go back, click on Playlist, you can see how this lightboxMode effectively 54 00:04:10,020 --> 00:04:13,530 looks like a video that is for all intent purposes 55 00:04:13,530 --> 00:04:15,940 is playing over the top of our activity. It's an 56 00:04:15,940 --> 00:04:20,550 interesting effect there, but obviously it's still working in portrait mode which is good. 57 00:04:20,550 --> 00:04:25,980 So what's happening here is that Google had prevented the activities in their player from being destroyed 58 00:04:25,980 --> 00:04:27,870 when the orientation changes. 59 00:04:27,870 --> 00:04:30,720 And as I mentioned we will be seeing how to do that ourselves. 60 00:04:30,720 --> 00:04:35,700 So as a result of doing that, Google have also had to write code to cope with the change of orientation, 61 00:04:35,700 --> 00:04:40,020 and resize their layout themselves instead of relying on the default behavior. 62 00:04:40,020 --> 00:04:46,200 Now when the lightboxMode isn't used, the activity makes no attempt to handle the resolution change, 63 00:04:46,200 --> 00:04:51,630 which is why we get a landscape screen on the side. But in lightboxMode, Google have to deal with the resizing 64 00:04:51,630 --> 00:04:56,280 themselves, so it can be done if you decide to do that but it's quite a bit of extra coding. 65 00:04:56,280 --> 00:04:59,010 Alright, so that's the solution, or our solution to the challenge. 66 00:04:59,010 --> 00:05:01,820 Congratulations if you managed to complete it. 67 00:05:01,820 --> 00:05:06,140 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 68 00:05:06,140 --> 00:05:09,340 saw a few videos back. So I'll see you in the next video.