plyr icon indicating copy to clipboard operation
plyr copied to clipboard

Plyr Youtube is WebView ready?

Open MrProLopstar opened this issue 5 years ago • 33 comments

Faced a problem, Plyr in WebView conflicts with youtube and won't start it.

MrProLopstar avatar Oct 25 '20 18:10 MrProLopstar

I'm facing a similar problem. I'm facing this problem in low end mobile browsers (MIUI browser, Vivo browser, Opera MINI). They all are WebView based. The Youtube embed does not play 😭 no matter what you do.

deepansh96 avatar Nov 12 '20 18:11 deepansh96

Just found out that the video plays if the video is muted

deepansh96 avatar Nov 12 '20 19:11 deepansh96

I want to use the player for VK Mini Apps, most likely its webview is based (in my case) on the standard MIUI browser. I tested, yes, with the sound turned off, the video starts (if you turn it on again, then the playback stops).

MrProLopstar avatar Nov 13 '20 07:11 MrProLopstar

One possible hack is to create a separate Plyr instance, which will stream the audio of that YouTube video.

The audio of the original Plyr will stay muted.

But this will require a lot of work :/

deepansh96 avatar Nov 13 '20 07:11 deepansh96

I also checked that everything works stably on the iPhone, the problem is only on Android.

MrProLopstar avatar Nov 13 '20 07:11 MrProLopstar

Well, such an idea .. Will not it be asynchronous?

MrProLopstar avatar Nov 13 '20 07:11 MrProLopstar

  • will have to turn off the sound in the main player, and this can confuse the user.

MrProLopstar avatar Nov 13 '20 07:11 MrProLopstar

Is it possible to intercept youtube events, functions and manually include video when receiving a "play" plyr event? I just looked like that, with sound plyr thinks that the video is running, but YouTube is paused.

MrProLopstar avatar Nov 13 '20 08:11 MrProLopstar

Yes we can intercept YouTube's events and we can also control things

Go to the embeds section in the readme https://github.com/sampotts/plyr#embeds

Let me know if you find something! Will keep looking at this

deepansh96 avatar Nov 13 '20 08:11 deepansh96

I tried this method and it still didn't work. I even added a separate button, which will serve the purpose of a user action, and it appears whenever the video is paused. Even that didn't work. Still banging my head trying to figure it out.

@sampotts Apologies for the unnecessary tag but can you look into it?

I just want to know if it's even possible to fix it right now or should I give up on it and come back when there's support for this.

deepansh96 avatar Nov 14 '20 04:11 deepansh96

@deepansh96 , please check out this article: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes. We need to figure out how to allow the user to make the first click on the Youtube player itself, and not on the Plyr shell.

MrProLopstar avatar Nov 20 '20 11:11 MrProLopstar

But how will we be able to do that? We can only do that via the YouTube IFrame API, because the youtube play button is not exposed, only the Plyr shell's button is.

I tried doing this -> On the event of clicking the Plyr shell play button, i tried calling this.player.embed.playVideo() and it doesn't work

deepansh96 avatar Nov 20 '20 16:11 deepansh96

I tried it too, I also listened to Plyr events, it didn't work either. I tend to believe that you need to actually press the player itself, and not the extraneous buttons. We need to figure out how to make access to the Yotube player bypassing the plyr css trap before the first launch of the player. Also, in the process of writing the text above, I had the idea that at the first start, you can simply insert the YouTube player, and then with the next Plyr changes, but this is a crutch.

MrProLopstar avatar Nov 20 '20 20:11 MrProLopstar

Chrome, Edge, Firefox None of these browsers block it then why does WebView blocks it? And some WebView versions actually allow it to play, and some don't. I'm not too experienced with frontend development so I'm just trying what comes to my mind!

deepansh96 avatar Nov 21 '20 03:11 deepansh96

I'm not good at this either, but as for me, WebView works relying on the stock browser (in most cases, Chrome). And if it works, then only on old devices with chrome release before 2017. According to their policy, "background playback" is allowed only when the user clicks on the player itself. without this, the video can only run in a muted state. We need to figure out how we can allow the user to make the first click on the Youtube player, and not Plyr.

MrProLopstar avatar Nov 21 '20 19:11 MrProLopstar

The users of our app also has this issue. So far it is proved on Android 7 and Android 10. I haven't tried on other devices.

jemunk avatar Nov 27 '20 07:11 jemunk

The question is in the policy of Google Chroome and similar browsers, they have limited "background playback" for any players without physical pressing.

MrProLopstar avatar Nov 28 '20 05:11 MrProLopstar

I also came to the same issue. At first, I thought it's some internal issue with my script. So I tried with plyr and videojs. Both are having the same issues. Did anyone figure out the solution yet?

Quuantum-Studios avatar Jan 05 '21 20:01 Quuantum-Studios

I have only come to directly inserted links to YouTube's video, but it is impossible, so that..

MrProLopstar avatar Jan 13 '21 09:01 MrProLopstar

any solution to show original youtube iframe? No matter what i do, it does not work. Only solution is to make video muted.

bbevren avatar Jan 26 '21 12:01 bbevren

I set up a server-side YouTube direct link parser that is updated periodically. If necessary, I can later throw off the link to the example of my api

MrProLopstar avatar Feb 01 '21 11:02 MrProLopstar

I did the same thing. I used the youtube-dl to parse and store the direct video source link from youtube and loading it as usual in the plyr. But the question is, if we have to do all this work then what's the use of youtube functionality in plyr and we would also get dependent on the youtube parser which needs frequent updates and is against youtube's policy. I just want to use the youtube iframe directly.

Quuantum-Studios avatar Feb 10 '21 18:02 Quuantum-Studios

Same. Tried the youtube-dl parser at the server side, spent a whole day setting it up but there a clear issues with that method.

  • YouTube keeps updating their schema. Something that works right now might break next month
  • Getting a direct source link might work for older videos, but the newer videos are stored in 10 second segments. You will have a root URL and a suffix URL for each segment. Rendering that on Plyr will be a pain

deepansh96 avatar Feb 11 '21 09:02 deepansh96

Hello, has anyone found solution for this?

kzr4tama avatar Apr 29 '21 22:04 kzr4tama

Hello, has anyone found solution for this?

Nope, only if you parse YouTube directly

MrProLopstar avatar Apr 30 '21 10:04 MrProLopstar

Issue: if plyr or any other video player is used in website and video can’t be played by tapping on play ️icon typically it throws the following error in android logcat: play() can only be initiated by a user gesture, source: either it will be vimeo.js or youtube etc

Solution: add webViewSettings.setMediaPlaybackRequiresUserGesture(false); in your android code (where your webview code is)

@MrProLopstar @kzr4tama @jemunk @toppersdesk @bbevren

aneeskhan47 avatar May 29 '21 10:05 aneeskhan47

Solution: add webViewSettings.setMediaPlaybackRequiresUserGesture(false); in your android code (where your webview code is)

Has anyone tried it? Does this work?

Vetronus avatar Jan 11 '22 05:01 Vetronus

Solution: add webViewSettings.setMediaPlaybackRequiresUserGesture(false); in your android code (where your webview code is)

Has anyone tried it? Does this work?

yes i tried it and it worked

aneesdev avatar Jan 12 '22 15:01 aneesdev

@aneeskhan47 I have a normal React web application, I probably can't call this function, although I'll try. At the moment, the sound starts, but after the initial loading of the video, before that I parsed the video from YouTube directly, but this turned out to be a less effective method. Also, at the moment, I can't update Plyr, because. gives a critical error in the CSS file. I still updated and pasted the CSS from the old version, I don't know if I did it right

MrProLopstar avatar Jan 13 '22 06:01 MrProLopstar

while using webview set mediaPlaybackRequiresUserAction to false

singhsonukumar6 avatar Feb 20 '22 11:02 singhsonukumar6