[MUSIC PLAYING]
JAREK WILKIEWICZ: Hello, and welcome to
YouTube Developers Live.
I have an exciting show for you today.
In London, we have Ross McIlroy.
How are we doing, Ross?
ROSS MCILROY: Doing good.
Thanks.
How are you?
JAREK WILKIEWICZ: Doing great.
And my name is Jarek Wilkiewicz.
I work on YouTube Developer Relations.
Today, we'll talk about the YouTube Android Player API.
If you have watched our Google I/O presentation, you might
actually recognize Ross, who was one of the presenters at
that session.
I understand you've been quite busy since Google I/O, Ross.
That was earlier this year.
Can you tell us what you've been up to?
ROSS MCILROY: Sure.
So we've been working with some trusted testers on
refining the API, making sure it works well, adding some
missing features, and making sure that all of the bits are
in place to make sure we can enable you to play all the
YouTube content embedded within your app.
So just final polishing and ready for launch.
JAREK WILKIEWICZ: Great.
So I know that you have built a set of demos to help
application developers use the API.
Should we look at a couple of the examples that are included
as a part of the release?
ROSS MCILROY: Sure.
JAREK WILKIEWICZ: OK.
Let's start with the video wall.
I'll launch it right now.
ROSS MCILROY: Sure.
So the video is an example of what you might be able to do
with the app by putting all the
components of the API together.
So it's a simple demo of thumbnails flipping.
And then one of the thumbnails will flip in
and turn into a video.
So that shows you how you can embed the videos within your
UI and play and pause them programmatically.
JAREK WILKIEWICZ: Great.
And moving along, there is a simple player view demo
included as well.
Can you tell us when one might want to include this code?
ROSS MCILROY: Sure.
So the simple player view is just the simplest possible
approach to using the API with embedding a
video into your app.
So this is just embedding a simple player
view into the UI.
I have nothing else apart from text here, but you could put
whatever you want above.
And it's just showing how simple it is to embed the
player view.
We also have the simple player fragment, which is basically
the same demo but using YouTube player fragment as
opposed to player view.
You might want to use that if you need to
extend a different activity.
For the player view, you need to extend our activity that we
provide as part of the API.
The fragment, you could extend any activity you like and just
embed the fragment.
JAREK WILKIEWICZ: Great.
And custom player controls.
ROSS MCILROY: So this is just a demo of wiring up UI
controls to the programmatic elements of the player.
So you can play/plause with the buttons, which are under
your control.
And underneath, we have an event log, which is showing
the various callbacks that you can register and listen for,
for example, playing videos, seeing when the video's ended,
when the user has pressed pause, et cetera.
JAREK WILKIEWICZ: Great.
And I understand you've made some improvements to
full-screen handling, which is something that is always very
tricky for developers.
Custom full-screen handling illustrates that one.
ROSS MCILROY: It does.
Yes.
And by default, full screen is a dialogue which appears on
top of your activity.
And so that works very well, but it sometimes introduces
some buffering.
So custom full screen shows our best practices on how to
deal with full screen.
And so in that case, you have to manage the [? relay out ?]
to full screen yourself.
But by doing that, you get a really smooth transition to
full screen with no buffering.
JAREK WILKIEWICZ: Indeed.
And there is a demo that shows you how you can actually
include full screen in your application here.
Is that the overlay action bar demo?
ROSS MCILROY: Yes.
So the overlay action bar demo is just showing how you can
overlay an action bar on top of the player [? palettes ?]
in full-screen mode, as long as the action
bar has overlay set.
And so this is to enable you to, for example, have some
custom buttons in the action bar to enable some control for
your app and [? palettes ?] in full screen.
Because we don't need allow you to overlay any custom
views on top of the player itself other
than the action bar.
JAREK WILKIEWICZ: Right.
And then I've seen applications performing video
playback into a lightbox.
Which demo actually shows that feature?
ROSS MCILROY: So that's the standalone player demo.
And so that one's just showing a different approach to
playing video, which is not embedding it in your UI but
instead launching a separate activity.
So it's much simpler to do, but you don't get as much
flexibility or control.
So if you click the lightbox mode, and you play the video,
you can see the video appearing above
the underlying activity.
So that's a good option if you want to just show a quick
preview of a video alongside your UI.
JAREK WILKIEWICZ: OK.
Great.
And these examples are packaged together as a part of
the API release, right?
ROSS MCILROY: Yeah, that's right.
We provide them in the library.
So you can get going.
JAREK WILKIEWICZ: OK.
Let's walk through the API.
So can you tell us a little more about what is the process
of integration between this API and one's Android
application?
ROSS MCILROY: Sure.
So once you the zip, you'll have the sample apps and a
library directory, which contains the JAR of the API.
And so to embed the API in your own application, all you
need to do is take that JAR, copy it to the LIBS directory
in your project root.
And if you have any clips-- or [INAUDIBLE], I think, as
well-- it will automatically add that
to your Java classpath.
And then you can just use it straight away.
It's already in your app.
One thing you'll need to do is register for a developer key
on the Google APIs console.
And so once you've done that, you can initialize the API and
make use of it.
JAREK WILKIEWICZ: Great.
And then there's actually four different ways in which video
playback can be incorporated into your Android application.
Can you walk us through the API?
I know we have Java docs with all this information.
Maybe real quickly show us what are
kind of the key classes.
ROSS MCILROY: Sure.
So the final demo we showed there was
the standalone player.
So this is the class for the standalone player.
You can see the code here.
We have an example fragment.
It's just two lines of code to create that standalone player.
Just pass in your video ID that you want to play.
And there's various different intents you can create with
this class to play videos or playlists or use
the lightbox mode.
And then once you start the intent, that will throw up the
activity, which will play the video.
So that's a really simple but less flexible
way of playing videos.
If you want to really embed the YouTube videos into your
UI, we provide these three classes.
There's the player view, the player fragment, and the
player support fragment.
So they all effectively act in the same way.
They provide a view, which you can inflate in your app UI or
programmatically instantiate.
Once you have that, you call the initialize method on that
UI element, pass your developer key on
InitializeListener.
And then you'll get a call back through your own
InitializeListener about when you've succeeded in
initializing the API.
And with that callback, you'll get one of these YouTube
player objects.
And so the YouTube player object is basically the main
object in the whole API.
So this allows you to control video playback in those UI
player views or player fragments.
And so you can load videos, queue videos, skip between
playlist elements, and seek the video, do all the things
you would expect from such an API.
And also register for various callback events, playback
events, or changes in the player state
or full-screen events.
And so the final way you can play YouTube videos using this
API is through the YouTube intents class.
And so this is basically just a convenience mechanism to
enable you to create intents which will launch the YouTube
Android application itself.
So a lot of people have been using this in the past to play
videos by building their own YouTube URLs and passing that
as the intent.
This just creates a standardized way of doing that
with various options for starting the video in full
screen or playing playlists or opening a user's activity in
the app itself.
JAREK WILKIEWICZ: YouTube standalone player is the
simplest way to get started.
Player view and player fragment will alone one to
build a more sophisticated user interface.
And then YouTube intents class basically wraps the intents
that are available from the YouTube app.
And it just invokes the app from one's application.
ROSS MCILROY: Yeah.
Exactly.
JAREK WILKIEWICZ: Great.
And you mentioned that as a part of the initialization
process, one can actually encounter various error
conditions.
Can you quickly walk us through what these errors are
and what are the best practices
around handling them?
ROSS MCILROY: You get this on-initialize failure result,
which will provide a YouTube initialization result
alongside the callback.
So this is an enum that has various options
for what went wrong.
And so various things could go wrong in
connecting to the API service.
So one of the ones which you could encounter is
DEVELOPER_KEY_INVALID, if you've not got a valid
developer key, or INVALID_APPLICATION_SIGNATURE.
So we require that your application's APK has been
signed in the same way that it would be signed to be uploaded
onto the Google Play Store.
And then there's various other ones, which can be
recoverable.
So this example is a SERVICE_DISABLED,
SERVICE_MISSING, or SERVICE_VERSION_
UPDATE_REQUIRED.
So if you get one of these initialization results, then
the method issues a recoverable
error will return true.
And so this means that there's something that the user can do
to make the API work.
And so what they may have done is disabled the YouTube app.
Or they may have uninstalled it.
Or they may have an old version which doesn't have the
API service available.
And so if you have one of these errors, you can call and
get error dialogue on the YouTube initialization result.
It will create a dialogue for you, which identifies the
problem to the user.
For example, they need to update the YouTube app.
And it gives them a button to press, which will take them
straight to market and enable them to update it there.
And once they return to your activity, we'll pass back the
request code that you've passed into the get error
dialogue on activity result.
And you can check whether the resolution was successful or
not, and if so, reinitialize the player
view or player fragment.
JAREK WILKIEWICZ: Great.
So sounds like the two common errors will be
developer key related.
So the API does require developer key, unlike the
existing player APIs.
In fact, I've noticed people that we've worked with
frequently run into this issue with
trying to run the examples.
So you actually have to go in and change the developer key.
And you can obtain that Version 3.0 developer key from
our developer console.
If you need to know more about YouTube Data API v3, go to our
blog, apiblog.youtube.com, where you will find a lot of
additional information.
This API was recently launched.
And then the other one, which is actually user recoverable,
is related to a version check that the API performs.
And this is where the application developer can
actually work in concert with the user and help the user
update the app if that is, in fact, necessary in order for
the API to function on the device.
And then the API supports Android Version 2.2 and above.
Is that correct?
ROSS MCILROY: Yeah.
2.2 and above.
Froyo all the way to Jellybean.
JAREK WILKIEWICZ: Great.
So another question I had about the API is, do you
support live stream playback?
ROSS MCILROY: So we support live stream playback.
But due to the video format that's used by YouTube, only
Android devices from Honeycomb MR1 and above will support
live videos.
So that would be version 3.1 of the platform.
If the devices is version 3.1 or above, they will be able to
play live videos.
Otherwise, they won't.
JAREK WILKIEWICZ: Great.
Speaking of compatibility, I guess the fundamental question
an application developer might ask is, is the library
compatible with my device?
Do I actually have all the prerequisites for
the library to run?
So how can one determine whether the library is
actually supporting one's device?
ROSS MCILROY: Sure.
Yeah.
So we provide this YouTube API ServiceUtil class.
And within that, there is a
isYouTubeAPIServiceAvailable call.
And when you call that, you'll get back again one of these
YouTube initialization results.
So that'll, again, either give you the success result, which
means the API's there and available, and you can use it.
Or it might give you one of the ones which you can
initialize a dialogue to enable the
user to recover from.
Or there may be some other error, which you can identify
and use another mechanism to play back the video.
JAREK WILKIEWICZ: Great.
And then As far as the initialization [? part, ?]
say if I'm working on an older Android device, is there
anything that I need to be worried about?
Can you tell us a little bit more about-- how long does it
take to initialize the library?
ROSS MCILROY: So the initialization is
asynchronous.
And the reason for that is it can sometimes take some time
to spin up the activity which the service is provided by.
So on older devices, if the YouTube app isn't already
running, it may take a second or so for that to happen.
Now, once that's happening, the UI of the player has a
spinner loading.
And it's not blocking the UI thread.
So it's not going to affect your
animations or your graphics.
But the player's not going to be available
until that's happened.
So if you are worried about this on older devices, what
you could do is hide the player view until
initialization successes come back and then load
the video into it.
But usually, it's just going to be under 200 milliseconds
or so in modern devices, at which point the player view
will be initialized.
And once you have one player view initialized, then the
service is already up and running.
It'll be much faster each time to connect.
JAREK WILKIEWICZ: Great.
And as you said, the whole process is asynchronous.
So the developer can actually trigger the initialization at
the best opportunity for a given application.
ROSS MCILROY: Exactly.
And the UI looks much the same while it's loading the service
as when it's loading the first video, buffering.
So there's a seamless transition there.
The user shouldn't notice a difference between the API
initializing and the first video buffering.
JAREK WILKIEWICZ: Great.
Well, thank you very much for your time, Ross.
I know you need to run off and do your holiday shopping.
Is that correct?
ROSS MCILROY: Yeah.
I've been too busy building the API to
do any holiday shopping.
JAREK WILKIEWICZ: All right.
Well, hopefully you will have enough
time before the holidays.
Thank you very much again.
And for those of you who are watching, thank
you for your attention.
And we'll see you again on YouTube Developers Live.
[MUSIC PLAYING]