sarbagyastha / youtube_player_flutter

A Flutter plugin for inline playback or streaming of YouTube videos using the official iFrame Player API.
https://youtube.sarbagyastha.com.np
BSD 3-Clause "New" or "Revised" License
692 stars 784 forks source link

AutoPlay not working [BUG] #582

Open Riyaz7364 opened 2 years ago

Riyaz7364 commented 2 years ago

Describe the bug I am using same code provide in Git but my video is not auto-playing like this example https://sarbagyastha.com.np/youtube_player_flutter/#/

I'm using chrome browser Version 96.0.4664.45 (Official Build) (64-bit)

Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 18116933e7 (7 weeks ago) • 2021-10-15 10:46:35 -0700 Engine • revision d3ea636dc5 Tools • Dart 2.14.4

jeromecaudoux commented 2 years ago

On my side, its working on Firefox but not Chrome and Safari.

BennyKirschner commented 2 years ago

can confirm, works in Firefox but not in Chrome.

BennyKirschner commented 2 years ago

found the issue - within player_frament.dart you have to set allow="autoplay" after "src="$sourceUri" within the iframe. Fixes the issue in Chrome.

JeanBarreiro commented 2 years ago

Could you provide a bit more details? I tried to reproduce but it only allows me to play the video after I press the play button. I am also on chrome and this is definitely still an open issue. Is there an hotfix?

BennyKirschner commented 2 years ago

image Check out the player_fragments.dart file. In line 39 you have to add the allow"autoplay" flag and you should be good

JeanBarreiro commented 2 years ago

Edit: I not sure if I am in the right place, mine appears in line 35?

image

mine appears in

image

Thanks for the feedback!

I notice that if you start the app without interacting with it it will still not load, if you click on the tab and reload it, it will load every time, weird huh?

I am trying to figure out if I can force play it using a bool forcePlay = true but am struggling with that as well.

SampatDixit commented 2 years ago

@Jankeelol were you able to force play the video on loading? Even I am struggling to get it force play

JeanBarreiro commented 2 years ago

@SampatDixit I was! The issue is that Chrome does not allow you to force play a video with sound.the work around that i used was to use firefox in the end device. Firefox allows you to force autoplay with sound. Otherwise, you need to mute the video in order for chrome to allow autoplay on loading the app

SampatDixit commented 2 years ago

@Jankeelol thanks..this helps !

kaciula commented 2 years ago

Autoplaying with sound on Chrome works if you add allow="autoplay" (as suggested in a previous comment) AND you click anywhere on the Chrome page before video starts autoplaying. I guess Chrome only allows autoplay with sound on current active tab.

So my dilemma right now is how to simulate a click on the page from code. I've tried setting focus to the page but it did not work. Any ideas?