2011-07-19 74 views
1

我想在UIWebView中嵌入一個YouTube視頻並讓它自動播放。顯然這不起作用。這是涉及到:嵌入式Youtube不自動化在UIWebView中的視頻

http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html

或者是某種錯誤的?

這裏是我的html文件:

<html> 
    <head> 
     <script> 
      document.ontouchmove=function(e){ e.preventDefault(); }; 

      </script> 
     </head> 
    <body style="margin:0px;" bgcolor="#000000"> 
     <!-- 1. The <div> tag will contain the <iframe> (and video player) --> 
     <div id="player" style="text-align:center;"></div> 

     <script> 
      // 2. This code loads the IFrame Player API code asynchronously. 
      var tag = document.createElement('script'); 
      tag.src = "http://www.youtube.com/player_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 onYouTubePlayerAPIReady() { 
       player = new YT.Player('player', { 
             height: '400', 
             width: '768', 
             videoId: 'HYlD0KXujAk', 
             playerVars: {'autoplay' : 1}, 
             events: { 
             'onStateChange': onPlayerStateChange 
             } 
             }); 
      } 


      // 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) { 
      } 
      function stopVideo() { 
       player.stopVideo(); 
      } 
      </script> 
    </body> 
</html> 
+0

你能告訴我你是如何解決這個問題的嗎? – Cyril

回答

-1

不,這是沒有錯誤,這是默認的行爲。 UIWebView不會無需用戶干預自動播放任何東西,除非你設置UIWebViewmediaPlaybackRequiresUserAction屬性NO(這是YES默認)自己。然後它會工作。

+0

我試着將屬性設置爲NO,但它沒有改變任何東西:( –

+0

不!我已經說過它不是默認設置!你需要將它設置爲YES!:P – Pripyat

+2

不會改變一個東西:( –