I have created app that uses iframe to load youtube video. The video shows up but it’s not autoplaying despite the autoplay=1 parameter being present in the iframe.
I’m doing this on iOS. I have set following preferences in config.xml:
all to no avail. When i click on a button that takes me to the page which has the iframe, the page opens up but youtube video is just there, no auto playing.
then i have to click on the video to get it started. I want it automatically started so that to watch a video, user doesn’t have to click twice on a video.
The example works for sure. It must be something in your configuration. Are you sure you added the cordova-plugin-whitelist to the project?
Also, have you checked if the Chrome console displays errors when you do the remote debug.
Instructions on how to setup remote debugging:
yes i have checked the console. there’s no error. the weird thing is that the same page works when i run it in chrome browser. but when i run it in the app (cordova ios project) the video doesn’t auto play.
here’s what i’m doing:
i click on a button ‘show video’
the link opens a modal view page that contains the iframe view
the page opens up and the video thumbnail is shown (but it doesn’t auto play)
i click on the video thumbnail which then expands and plays a video.
if everything works fine, on step 3 the video should play right? but it doesn’t in my case.
also, when i said that nothing happened, i was talking about my app not your example. your example surely works. and that’s exactly i myself had set it up while trying to make this work with iframe api. you also probably have taken the example from the same place i took: first example on the google iframe api reference. it worked on simple webpage, but didn’t in my ios project.
I don’t have an iPhone with me to try this, but on iPhone 6 Simulator example is working. The video player is presented in fullscreen (like explained in iOS-Specific Considerations -> Optimization for Small Screens), but auto start is working.
MediaPlaybackRequiresUserAction (boolean, defaults to false): Set to true to prevent HTML5 videos or audios from playing automatically with the autoplay attribute or via JavaScript.
AllowInlineMediaPlayback (boolean, defaults to false): Set to true to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the webkit-playsinline attribute to any <video> elements.
I have a strange problem on my application.
I’ve created a youtube app by following this tutorial: http://bit.ly/2dXWVAL
Then uploaded it to Google Play. But it’s rejected, because it continues to play in the background when screen locked. But it pauses when I press home button.
I tried to fix it with cordova pause event on scope and ionicplatform ready. But it’s not successful.
I’m quite surprised it didn’t work out well for you. Mine pauses on lock and on minimize
I had a brute way to make sure all iframes stopped playing on pause. Here’s a sample directive I created and used. All my youtube iframes have the ‘yt-frames’ class.
// PAUSE any player when app minimized
function onMinimize() {
var frames = document.querySelectorAll('iframe.yt-frames');
if (!frames || !frames.length) return;
for (var i = 0 ; i < frames.length; i++) {
frames[i].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
}
}
// 'pause' event called when app is minimized
document.addEventListener("pause", onMinimize, false);
$scope.$on("$destroy", function () {
document.removeEventListener("pause", onMinimize, false);
});