0

デモでは、クロムレスYoutube プレーヤーを開発しようとしています。そのリンクのコントロール リンクは、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();

  }

}
4

1 に答える 1

4

これらの呼び出しを置き換えます (オブジェクトの呼び出しytplayer):

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

以下を使用します。

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

Internet Explorer はytplayerオブジェクトを HTMLCollection として 扱います。ここに画像の説明を入力

要素を明示的に選択すると、関数を呼び出すことができます。

于 2012-12-12T22:56:02.297 に答える