How to play YouTube videos in background in android?
Asked Answered
T

4

9

I'm a beginner and I’m working on an android project in which I play youtube videos using Google YouTube data API. Is it possible to play the video in the background even after the user has switched to another app or pressed the home button? Is it possible to separate the audio from the video and stream that in the background? I don't want to use web view.

Trottier answered 10/2, 2017 at 13:49 Comment(0)
P
4

It is possible to play the audio in the background. However , you are not allowed to do so.

This violation of the Youtube API is cause for immidiate removal from the play store.

Official answer:

During review, we found that your app violates the Prohibited Actions provision of the Content Policy.

We have determined that your app enables background playing of YouTube videos, which is a violation of the YouTube API Terms of Service: "Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to: (8) separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API;"

Penuche answered 10/2, 2017 at 13:58 Comment(8)
so if i play youtube videos without using youtube api would that be a violation too? Although i'm not sure if that's possibleTrottier
Yes, I used youtube inside a webview with an iframe and that's not allowed eitherPenuche
But there are some apps that provide this feature right?Trottier
Not to my knowledge, can you name an example? You would get away with it maybe, if you don't release your app to the play store , but instead release it on those other app stores. But that's not what you want.Penuche
I just learned the app was talking about doesn't actually play the video in background, instead it plays the video in a floating window.Trottier
yes, sorry about that, got a bit busy. It's not the answer I was hoping for but i guess it's the only answerTrottier
What if I create an app that allows to play youtube in background without publishing the app - only for my needs?Skeens
@Skeens If you're using the API , you need a key. I guess they will block your key when abusing the API. If you're playing it in another way in the background, I don't know what steps they will take, but I'm not sure if you will get away with it indefinetelyPenuche
C
1

youtube red users only they possible to play youtube videos in background (https://support.google.com/youtube/answer/6308116?hl=en). You can check if they have this in the api,

its possible to play youtube videos in background if you open the desktop version of youtube in a browser. Maybe you can make use of this by opening the correct link in a webview in background

Canonical answered 10/2, 2017 at 14:8 Comment(0)
S
1

I got another idea, but not sure will it violate the rule.

You can build your own service base on youtube-dl. More explain step by step:

  • First you got the url of the video from Youtube

  • Second you extract the audio information from the origin video url, and you now get the audio source via youtube-dl

  • Play the audio source in the background

In this way you are not using the Youtube api directly, I think it's fine to only use the audio from the source and play it in the background.

Shabby answered 10/1, 2020 at 9:52 Comment(0)
T
0

Yes its possible and its easy. No installation, no root, no violations. Let me explain it.

Andriod 9 --> Settings --> Search Picture in Picture --> select YouTube --> Allow

Once Allow picture-in-picture is enabled. You can run YouTube in Background.

enter image description here enter image description here

Tedder answered 10/1, 2020 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.