How to bypass Chrome disabling autoplay of video's in background tabs - javascript

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

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.

Related

About using YouTube API on TV

My question is related to developing HTML5 based apps for TV, using YouTube API to play videos. I've tried to find Google forum to post my question, but they recommend it here. Currently IFrame API is the recommended way. However, I would like to know the extents and proper way to use it for TV. It seems to me that embedding videos on TV will greatly limit possibilities for user. So to concrete questions:
How to avoid "Playback on other websites has been disabled..." error? I'm not playing back from website after all. Meanwhile XBMC/Kodi can playback those videos just fine. Are they using some old deprecated API? I've tried to set origin var in playerVars to https://www.youtube.com/tv, but then the player object is failed to initialize.
How the advertisements are going to be presented/interacted? So far I haven't seen anything with "Skip Ad" button using IFrame API. Only small banner image on left bottom side. But on TV there is no way to click on it. YouTube original TV app is showing "Skip Ad" type ads. Is there some special way for TV apps to present ads in proper way for devices with limited input, like TV?
Similarly the 'i' button appearing on top right side is not useful at all on TV. How to avoid it as well?
So I would like to know the extents I can achieve in my HTML5 based app, presenting YouTube videos, comparing to native YouTube application. Both the legal way and the tricks to achieve best experience for TV users are in interest.

How to mute the current tab or block sound for a web site?

I'm looking for a way to mute sound or block it from unauthorized sources,
The problem is that Google Ads is randomly playing videos in ads (very annoying)
For example, I want users to be able to play videos on my web site (I can add a special ID to these allowed elements or data-allowed-element).
I'm wonder if I can hookup to a browser sound event or detect when sound is playing - JavaScript?
Any ideas?
No there is currently no way to detect this browser independent! - There is no event or something else.
Furthermore i dont know exactly how the Google Ads works. I think they are running in an iframe or something which make it harder to detect/mute it.
But may it runns within an audio or video tag, so you can may mute it using the following post. But be careful - You have to mute the video and audio tags within the Google Ads iframe and not within your main window, because then you will have no effect.
https://stackoverflow.com/a/14045788/4275911

How does Myspace refresh page without stopping music playback?

I have been using the new Myspace for quite some time now, and I am really astonished on their design. It is really elegant and they have taken advantage of many HTML5 features. However there is one thing that, to me, outshines any other functionality and that is how you could navigate through myspace without having to stop the music playback. I noticed this a few days ago while listening to music, I changed the page and the music player would not reload. It would stay on its fixed position and the music would still play, even while the page was refreshing. And even if you log out, when you log back in the music player would play last song you were listening at exactly the time you left it on.
Now long story short, my question is: How do they achieve this? I am guessing they are saving the current track position in a cookie variable or in the local storage as it is playing, but what about the music player? How come it does not stop playing the song when navigating through myspace? Are they using any html5 feature to do this?
*note: I was inspecting their code because I thought they were using the jquery.load() function, but did not find any trace of that
Thanks to the insight given by #putvande, this Myspace feature is achieved using the HTML5 History API to change the browser URL without refreshing the page. Combining this with JQuery $.ajax can produce the effects shown in myspace, github and facebook. "arundavid" has a great explanation on this link at tinywall.info

Embeded youtube view gets counted with Javascript API but not with IFrame

*Situation is -*I have to design a webpage that works on both desktop and on mobile devices, that plays an embeded youtube video (not autostarted) which then i can use interact with the video to get the play state etc (using this to count the total time watched, excluding pause/buffer/stop time)
I've managed to build the website using both the IFrame API and Javascript API from Youtube.
*However the problem is-*With Javascript API, the player on the desktop works and the view gets counted too but it doesnt work when i view it on a mobile device. The place where it should show the video (the div tag) doesnt react.
With the IFrame API, everything works in terms of functionality but when i press play on the video, the views do not get counted - accessed from both desktop and mobile. I've tested the viewcount several times, with different IP etc but while javascript API web gets counted instantly, IFrame API web is still not getting counted..
Does anyone have any suggestion to this problem?
Just to remind you, the crucial aspect of the webpage that i need are:
Embeded Youtube player
Being able to interact with the player (e.g. getState() or getDuration())
Website fully functional with mobile access
Valid view count
Thank you all in advance!! :)
Are you sure that the views are really being counted via the javascript api? I have always read that view counts only are considered valid when initiated using the actual YT play button. Meaning you can't initiate play via any API call and have the view count.
Here is a a somewhat dated blog post from Google/Youtube team explaining - https://groups.google.com/forum/#!msg/youtube-api-gdata/7SsbvOJMWL0/rBCBqnFaxRgJ
I'm trying to find something that says this has changed but so far no luck.
** EDIT **
So I went back to the iFrame and Javascript API pages and if you do a search for 'view count' the first piece of content you'll find is a line stating --
"Note: A playback only counts toward a video's official view count if it is initiated via a native play button in the player."
Re-reading your post I'm not sure if you are using the API's to play the video or just to get data from its current state. If you are using it to actually initiate play then the view counts are not actually being counted. If you are seeing something different I'd love to see and learn from it.

Javascript threading issue with soundcloud's sc-player playback?

This is an interesting and weird problem, and I'm really not sure what's going on here. Maybe someone can offer me some insight. I have a simple form with a list of songs from both youtube and soundcloud. When the user clicks on one of the links(songs), it sends an ajax call to a script containing the essential ingredients of either a custom html5 youtube player (based on the Tubeplayer plugin), or a custom html5 soundcloud player (based on soundcloud's custom sc-player plugin).
The ajax calls work great. When the user clicks a track in the list, the appropriate plugin pops into the specified div and begins to play the song or video. There is a really wierd issue I'm having however. When I go from a youtube video to a soundcloud song, it works great. The youtube plugin is completely replaced by the soundcloud plugin. Playback on youtube stops and playback on soundcloud begins. But when a soundcloud song is playing and I click a youtube track in the list, the youtube plugin shows up and begins to play, but the soundcloud track continues to play also, even though the content in the div has been completely replaced with the youtube plugin via ajax.
I even tried taking the calls to the soundcloud plugin's js files and putting them into the script that the ajax calls to, so that even they would be replaced when the youtube plugin is called, but I'm still having the issue. Any idea as to what might be going on here? I'm really not very knowledgeable about jquery. Thanks in advance!!

Categories

Resources