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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.