gpt4 book ai didi

javascript - YouTube 播放器 Internet Explorer 故障

转载 作者:行者123 更新时间:2023-11-28 16:08:38 25 4
gpt4 key购买 nike

关于demo我正在尝试开发一个 chromeless Youtube 播放器。控制链接 that link在 Firefox 和 Chrome 上运行良好,但在 Internet Explorer 上不起作用。我该如何解决这个问题?我认为问题与 id 有关,但也许我很困惑,因为我尝试过的任何方法都不能解决我的问题。

  var ytplayer_playlist = [ ];
var ytplayer_playitem = 0;
swfobject.addLoadEvent( ytplayer_render_player );
swfobject.addLoadEvent( ytplayer_render_playlist );
function ytplayer_render_player( )
{
swfobject.embedSWF
(
'http://www.youtube.com/apiplayer?video_id='+ ytplayer_playlist[ ytplayer_playitem ] + '&enablejsapi=1&autoplay=1&loop=1&version=3&rel=0&fs=1&playerapiid=ytplayer',
'ytplayer',
'400',
'225',
'10',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer'
}
);

}
function ytplayer_render_playlist( )
{
for ( var i = 0; i < ytplayer_playlist.length; i++ )
{
var img = document.createElement( "img" );
img.src = "http://img.youtube.com/vi/" + ytplayer_playlist[ i ] + "/default.jpg";
var a = document.createElement( "a" );
a.href = "#ytplayer";
//
// Thanks to some nice people who answered this question:
// http://stackoverflow.com/questions/1552941/variables-in-anonymous-functions-can-someone-explain-the-following
//
a.onclick = (
function( j )
{
return function( )
{
ytplayer_playitem = j;
ytplayer_playlazy( 1000 );
};
}
)( i );
a.appendChild( img );
document.getElementById( "ytplayer_div2" ).appendChild( a );
}
}
function ytplayer_playlazy( delay )
{
//
// Thanks to the anonymous person posted this tip:
// http://www.tipstrs.com/tip/1084/Static-variables-in-Javascript
//
if ( typeof ytplayer_playlazy.timeoutid != 'undefined' )
{
window.clearTimeout( ytplayer_playlazy.timeoutid );
}
ytplayer_playlazy.timeoutid = window.setTimeout( ytplayer_play, delay );
}
function ytplayer_play( )
{
var o = document.getElementById( 'ytplayer' );
if ( o )
{
o.loadVideoById( ytplayer_playlist[ ytplayer_playitem ] );
}
}
//
// Ready Handler (this function is called automatically by YouTube JavaScript Player when it is ready)
// * Sets up handler for other events
//
function onYouTubePlayerReady( playerid )
{
var o = document.getElementById( 'ytplayer' );
if ( o )
{
o.addEventListener( "onStateChange", "ytplayerOnStateChange" );
o.addEventListener( "onError", "ytplayerOnError" );
}
}
//
// State Change Handler
// * Sets up the video index variable
// * Calls the lazy play function
//
function ytplayerOnStateChange( state )
{
if ( state == 0 )
{
ytplayer_playitem += 1;
ytplayer_playitem %= ytplayer_playlist.length;
ytplayer_playlazy( 1000 );
}
}
//
// Error Handler
// * Sets up the video index variable
// * Calls the lazy play function
//
function ytplayerOnError( error )
{
if ( error )
{
ytplayer_playitem += 1;
ytplayer_playitem %= ytplayer_playlist.length;
ytplayer_playlazy( 1000 );
}
}
//
// Add items to the playlist one-by-one
//
ytplayer_playlist.push( 'tGvHNNOLnCk' );
ytplayer_playlist.push( '_-8IufkbuD0' );
ytplayer_playlist.push( 'wvsboPUjrGc' );
ytplayer_playlist.push( '8To-6VIJZRE' );
ytplayer_playlist.push( '8pdkEJ0nFBg' );


function play() {

if (ytplayer) {

ytplayer.playVideo();

}

}



function pause() {

if (ytplayer) {

ytplayer.pauseVideo();

}

}



function stop() {

if (ytplayer) {

ytplayer.stopVideo();

}

}

最佳答案

替换这些调用(调用对象 ytplayer):

ytplayer.pauseVideo();
ytplayer.playVideo();
// ...

具有以下内容:

document.getElementById('ytplayer').pauseVideo();
// ...

Internet Explorer 将 ytplayer 对象视为 HTMLCollection: enter image description here

通过显式选择元素,您可以调用该函数。

关于javascript - YouTube 播放器 Internet Explorer 故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13849692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com