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);
});
I am still having an issue where the youtube video will not play programmatically after the playerReady event.
I am running the example code you provided on an iPhone running iOS 9.3.3
If I don’t use the playVideo() command, but instead tap the video, it plays fine.
When looking at the logs, the playVideo command initiates, and the video status changes from UNSTARTED to BUFFERING. However it never leaves the buffering state, and is compeletely unresponsive to user interaction on the phone. However, during buffering it changes from a mere loading symbol to a frame showing the start of the video.
Does iOS 9 not allow the programmatic start of videos even in a UIWebView? (Is that not what Ionic is housed in?) I have set the config option AllowInlineMediaPlayback to true as well as MediaPlaybackRequiresUserAction explicitly to false.
Found a solution:
We can’t detect a click in Iframe you better place a image or a button in iframe,In that button or image you can enable autoplay by playmethod & pausemethod.You can hide the button after a click is made by hide(). Hope it helps you!