PierfrancescoSoffritti / android-youtube-player

YouTube Player library for Android and Chromecast, stable and customizable.
https://pierfrancescosoffritti.github.io/android-youtube-player/
MIT License
3.43k stars 758 forks source link

Youtube video doesn't play in unMute mode in some updated Chromecasts #727

Open sergiambel opened 3 years ago

sergiambel commented 3 years ago

As you can read here https://developers.google.com/web/updates/2017/09/autoplay-policy-changes in some cases Chrome doesn't allow play video in "unmuted" mode.

Some Chromecast devices as Xaomi m2 devico or others Chromecast built in TV have the Chrome Webview updated and is not possible to run player.playVideo() method in JS to play the video. The only way to achieve the goal is run player.mute(); and player.playVideo();.

We tried to do a fork of your code testing other Youtube Iframe API implementations with no success. (for example adding allow="autoplay; fullscreen" to the player iframe implementation).

Any suggestion? Obviously, touch in play button or unmute button in video is not a solution because it is been played in the chromecast.

sergiambel commented 3 years ago

Added video to show the behavior in one affected Chromecast. We used your example apk for the demo:

https://user-images.githubusercontent.com/466578/115224930-c9f73400-a10d-11eb-8e86-67cade9c9b47.mp4

If we edit the receiver file and put player.mute(); before playvideo it plays well. We tested request player.unMute() with a settimeout and the video pauses :(.

PierfrancescoSoffritti commented 3 years ago

Hi, I am aware of this change of behaviour in Chrome. Have you done some research to see how other chromecast apps are solving it? The same problem should apply to any app that tries to play sound without user input.

sergiambel commented 3 years ago

Hi,

All apps we tested with Iframe payer have the same issue.

We have been searching some player alternative to suggest you to replace the current Youtube Iframe API, but we haven't found anyone. All players we tested used (internally) the Youtube Iframe API.

One option we've investigated is to emulate some kind of user click through CastSDK with no success. We didn't find the way.

Maybe we are in front of a Chrome bug or unexpected behavior. Do you know what could be the best place to report it?

PierfrancescoSoffritti commented 3 years ago

I meant other chromecast apps not related to YouTube. I assume this should be a common problem, on Chrome desktop no sound can be played without user interaction. I'm a bit surprised Chrome is enforcing this limitation on Chromecast too.

sergiambel commented 3 years ago

We have more information: The issue happens with Chromecast Built In devices at least with the App Chromecast Built in 1.52. If you go to settings > Apps > See All Apps > browse to the end until select "Show System Apps" and now find and select "Chromecast built-in" and select "Uninstall update". In our test device it back to 1.47 version and Iframe autoplay becomes running well again.

sergiambel commented 3 years ago

We tried to report it here: https://issuetracker.google.com/issues/185721623

PierfrancescoSoffritti commented 3 years ago

Nice, keep me posted.

sergiambel commented 3 years ago

A Google engineer said in the issuetracker that, this bug, is an intendeed behavior.

Let me invite you to enter here and add some comment to the mine:

https://issuetracker.google.com/issues/185721623?pli=1

PierfrancescoSoffritti commented 3 years ago

Hey, thanks for updating this. If they don't support iframes there's not much we can do i'm afraid

sergiambel commented 3 years ago

Dear @PierfrancescoSoffritti about this topic we have been thinking we could load the iframe player in the app and "intercept" or "parse" the video url stream to send it directly to the Chromecast Receiver.

There are Android apps (ie: browser) using this way with any issue. Maybe opening the player in the app and sending the video stream to the Chromecast would be compliance with YT terms.

PierfrancescoSoffritti commented 2 years ago

Hey @sergiambel did you have any luck with this?

sergiambel commented 2 years ago

hi, with no news :(

The last Chromecast built-in app versions continue showing the video as paused waiting for user click (impossible to happen in Chromecast). Any idea?

PierfrancescoSoffritti commented 2 years ago

I just tried running the sample app from chromecast yesterday, everything worked fine for me.

Could please check if it works for you? if it does, then maybe the issue you're having is in your code?

sergiambel commented 2 years ago

The issue happens in Android TV devices Chromecast enabled. As the last Chromecast version or any Android TV Smart TVs or Android TV Box.

To reproduce the problem: Use an Android TV device. Cast a youtube video. (The receiver will open a Chrome instance with autoplay disabled or enabled when video is muted)

If you go to settings and remove all Chromecast Built-in updates from your Android TV the cast will run fine. So the issue is with last updates of Chromecast Built In app.

Till date this issue doesn't happen in Chromecast 1st gen, 2nd gen, 3rd gen or Ultra.

PierfrancescoSoffritti commented 2 years ago

I see, unfortunately I do not own any android TV device. I was testing on Chromecast Ultra.

I will try casting straight to my TV and see what happens.