Я пытаюсь использовать a YouTube iframe API с моим проектом cordova-android. Когда я запускаю код в браузере на своем компьютере, он работает отлично, но когда я создаю свое приложение и запускаю его на своем телефоне, страница, содержащая iframe, не загружается, и я получаю следующую ошибку в моей консоли:Кордова/Телефонная губка Ошибка YouTube iframe_api: XMLHttpRequest не может загрузить хром-расширение. Запросы на кросс-начало поддерживаются только для HTTP
XMLHttpRequest cannot load chrome-extension://boadgeojelhgndaghljhdicfkmllpafd/cast_sender.js. Cross origin requests are only supported for HTTP
Вот мой код:
<div class='ui-body ui-body-a'>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
console.log('Loaded Video)
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</div>
заранее спасибо!
Я не мог заставить его работать, поэтому я закончил использовать плагин cordova [YoutubeVideoPlayer] (http://plugins.cordova.io/#/package/com.bunkerpalace.cordova.youtubevideoplayer). Но я оставлю вопрос открытым. – justahandsomeman