I need to be able to load videos in an element programmatically via the iframe api and get it to play on mobile (iOS 6, iOS 7, latest android).
Here is the javascript:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player
var ping = new VideoModel({
videoId: 'qMD2Jifubto',
start: 20,
end: 28
});
function VideoModel(attributes) {
this.attributes = {
videoId: attributes.videoId,
start: attributes.start,
end: attributes.end
}
this.get = function(attr) {
if (attr) {
return this.attributes[attr]
} else {
return this.attributes
}
}
}
function onYouTubeIframeAPIReady() {
player = new YT.Player('thumbnail-inner', {
height: '100%',
width: '100%',
enablejsapi: 1,
events: {
'onReady': onPlayerReady
},
rel: 0,
playerVars: {
controls: 0,
modestBranding: 1,
showinfo: 0
}
});
}
function onPlayerReady(event) {
event.target.loadVideoById({'videoId': ping.get('videoId'), 'startSeconds': ping.get('start'), 'endSeconds': ping.get('end'), 'suggestedQuality': 'large'});
}
This works flawlessly on desktop, but for mobile (testing on ios and android) the YouTube player DOES load but the video loads with 'video is not available', or is just a black screen.
Can you help to get this work on mobile?