Niranjan
Niranjan

Reputation: 1

YouTube LiveStream API - connecting device camera; obtaining output URL; compile errors in sample code

I am building an Android app which amongst other things will need to initiate a live video stream using the YouTube APIs available for this. I have reviewed the Google videos on this as well as leveraged the sample Java code as relevant. I have finally managed to get the basic code for the youtube build, live broadcast, live stream, the relevant inserts, the respective "returned broadcast / stream" and the bind statements into the code, with all the right libraries in place, I have 4 issues still open.

1) Nowhere in the sample code (or other sites I searched) did I find how to create a video stream out of the camera device and connect it up to the "input socket" of the above structure. There are web sites that show how to live stream from an Android device camera, but when I see that code I can't determine how to align that method (and into which variable) into the YouTube sample code.

2) Similarly, I cannot determine which variable will contain the "output socket" of the above structure - the URL that users can click to watch the broadcast,that I can then use in the subsequent steps of my App.

3) The "auth" class that is needed to get to the above stage was no available as a library. I finally pulled in the code provided on Github, and can take it from here if that's the only way, but is there an officially published library version of that class and its methods?

4) Last but not the least, while I say I have managed to get the code into the app and not showing missing libraries etc., it still won't build. The error is as follows, and again on searching Stackoverflow for these types of errors I could not get clarity on next steps.

Ideally I would like to address the above issues without changing or adding to the "tech stack" - for example there is mention of Python tools to extract URLs....I would rather get inside of how it is done and do it in Java code.

Hope to solve with the combined brain power of this forum! Regards

Upvotes: 0

Views: 679

Answers (2)

Ibrahim Ulukaya
Ibrahim Ulukaya

Reputation: 12877

The API only lets you create and manage livestreams ad events. After getting the rtmp address as ingestion address, you'll need to capture the camera yourself, then use one of the encoder/streamer libraries to actually stream to that address.

In the past I used ffmpeg libraries for that. I used Android ndk to build c++ code, and built into my app. Because of ffmpeg I couldn't opensource the project, but now I stripped of that part as interface, and hoping to opensource it in few days. I will update the question then.

Upvotes: 0

jlmcdonald
jlmcdonald

Reputation: 13667

I can answer the first two (but apologize ... as I'm not an Android developer I can't help much with the last two questions):

1) The YouTube Livestream API has no way in and of itself to actually stream the video; rather, when you issue the call to create the Livestream resource object, the returned object will have the following parameter:

cdn.ingestionInfo.ingestionAddress

You need to get whatever library and code exists on Android to create an RTMP stream and send it directly to that address which was returned (on YouTube's end, when you create that Livestream resource object it opens up the ingestion socket and, when your data starts coming through, it has all the info it needs to do all the transcodings and then rebroadcast it according to the parameters you set).

2) You'll want to work with two "output sockets," to use your term. First of all, when you create the broadcast resource (before creating the livestream resource), one of the settings you can pass is:

contentDetails.monitorStream.enableMonitorStream

If you set that to true, then the returned resource object will have an additional parameter:

contentDetails.monitorStream.embedHtml

That'll be a monitoring player, so whoever is doing the live broadcasting will be able to see the stream come up (once your app completes step #1) but before it may actually be live to the world.

In terms of the live-to-the-world stream, you can construct this ... the broadcast resource object's ID parameter will just be a plain old YouTube Video ID, so when that is returned (indicating the broadcast is set up), the watch URL will be:

https://www.youtube.com/watch?v={ID}

Upvotes: 2

Related Questions