Search code examples
androidaudiovideoyoutubebackground-process

Play audio from a Music Video using Youtube API in android, when my app is minimized


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


Solution

  • 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.