youtube_player_flutter
youtube_player_flutter copied to clipboard
AutoPlay not working [BUG]
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
On my side, its working on Firefox but not Chrome and Safari.
can confirm, works in Firefox but not in Chrome.
found the issue - within player_frament.dart you have to set allow="autoplay"
after "src="$sourceUri"
within the iframe. Fixes the issue in Chrome.
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?
Check out the
player_fragments.dart
file. In line 39 you have to add the allow"autoplay" flag and you should be good
Edit: I not sure if I am in the right place, mine appears in line 35?


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.
@Jankeelol were you able to force play the video on loading? Even I am struggling to get it force play
@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
@Jankeelol thanks..this helps !
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?