问题
my friends and I are making a website that acts like a radio station called Musare with playlists of YouTube videos that play after each other.
Recently Chrome introduced a new 'feature' that automatically disables autoplaying of videos in background tabs with no option to turn this off. This breaks our site because users don't want to keep going back to the site to start a song. This also broke other big sites, like YouTube playlists, Facebook chat notification sound and a lot of music sharing sites.
By now, a lot of sites have found solutions to bypass this, like dubtrack.fm, YouTube, Facebook and probably some other sites as well.
There is someone working on making an option for it at https://codereview.chromium.org/1414853003/, but that might take weeks or even months for it to be in the main Google Chrome.
If anyone knows how to bypass this, please let me know.
Thanks in advance :)
Already tried:
- Starting another video before the current one ends - no success
- Messing around with the Player Variables - no success
- Other things probably - no success
Extra notes:
- We are using the YouTube API. We use YT.Player and the youtubePlayer.loadVideoById(id)
- SoundCloud streaming works fine with SC.Stream.
- The source code for our project is at https://github.com/Musare/Musare
回答1:
So I have found out how to bypass it finally, after many hours of trying and researching.
If you just initialize the iframe player of YouTube by using the YT.Player
constructor, you can then just use the player variable and use yourPlayerVariable.loadVideoById(id)
.
You have to first go to the tab for it to start, but after that it will be able to load and play video's without you having to go back to the tab. If you remove and re-add the iframe, you will have to go back for it to start again.
来源:https://stackoverflow.com/questions/33787568/how-to-bypass-chrome-disabling-autoplay-of-videos-in-background-tabs