I am working on an app that uses the Youtube API. Since I'm concentrating mainly on MUSIC *VIDEOS* from Youtube, I need to play the audio of the video in the background when I navigate away from the app. But every time I navigate to another app, the video pauses. What can I do to get this issue fixed? Please help me. Thanks in advance
Play audio from a Music Video using Youtube API in android, when my app is minimized
Are you using a service to play the audio? –
Listed
No Lazy Ninja. Currently I'm playing it in an Activity. I could not initialize the YoutubeView from a service. –
Erme
From my understanding, the activity will pause when it goes to the background. Please refer to android activity life cycle.
When the activity goes to pause state, the video and audio linked with it will pause.
You will need a service to stream the audio in the background. And that's where it gets complicated.
Streaming audio inside a Service is a very easy task. The tough part is how to extract the audio from the video, and from this forum Youtube API is not keen on it.
The application PVStar+ does what you are looking for. But I have to figure out how they did it.
Thanks Lazy Ninja for the reply. link This app also seems to be doing it. But no idea how they are doing it –
Erme
Lately, I found out that, the audio should not be extracted from any of the Youtube audio visual content without Youtube's prior permission. link. –
Erme
Here is the solutio if somebody needs it: github.com/smedic/Android-YouTube-Background-Player/blob/master/… –
Horwath
© 2022 - 2024 — McMap. All rights reserved.