Wednesday, May 25, 2011

[YouTube-API] Re: HTML5 video playback on Android

I include sample code below that demonstrates the problem.

When Android HTML5 video player is started it remains in state 2 (paused) regardless of calling ytplayer.playVideo() or any other player functions.  I can manually click the "play" button in the video player to start playback.  However if I call ytplayer.getPlayerState() it still returns 2 (paused).

I also noticed that if calling ytplayer.playVideo() too fast (e.g. immediately in onPlayerReady() callback) I will get error requester saying "Cannot play video: Sorry, this video cannot be played.".
I also see this error: 05-25 13:27:25.289 E/browser ( 8447): Console: Uncaught TypeError: Cannot read property 'ud' of null http://s.ytimg.com/yt/jsbin/www-embed-vflBNdA1p.js:176

--
Tero


<html>
  <body>

<!--
To see device logs run:
adb logcat -v time browser:V MediaPlayer:V VideoView:V AwesomePlayer:V *:S
-->

    <div id="player"></div>

    <script>
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      var player;

      function onYouTubePlayerAPIReady() {
        console.log("onYouTubePlayerAPIReady()");
        player = new YT.Player('player', {
          height: '300',
          width: '450',
          videoId: 'u1zgFlCw8Aw',
          playerVars: {
            // Android does not obey autoplay=1 
            // *however* unless we define it here playVideo() will not work at all
            // in other words:
            // android html5 video player is not launched when calling playVideo() 
            // unless autoplay=1
            'autoplay': '1',
            'controls': '0'
          },
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange,
          }
        });
      }

      function onPlayerReady(event) {
         console.log("onPlayerReady()");
      }

      function onPlayerStateChange(event) {
         console.log("onPlayerStateChange(" + event.data + ")");
      }

    </script>

  <!-- Calling playVideo() will start android html5 video player but it remains 
       in "paused" state! User needs to click "play" again in the video player -->
  <button onclick="player.playVideo()">play</button>

  </body>
</html>

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment