Samsung Smart TV Play Youtube Video

codeTemplar picture codeTemplar · Jul 24, 2012 · Viewed 7.3k times · Source

I'm making a Samsung Smart TV application. I need to play youtube videos. Does anyone have any idea how to do this? I tried youtube js api but when the function playVideo() is executing the video just starts loading but not playing. I have Samsung Smart TV 2012 so the SDK is 3.5

Answer

Adam Lukaszczyk picture Adam Lukaszczyk · Jul 24, 2012

First of all check if your youtube video has granted access for mobile devices.

Second you have to disable advertisements on that video - as videos with advertisements doesn't work yet on TV devices.

Sometimes it takes a while after playVideo() to start playing the video, especially when you bind to some player events, so try to wait half or one minute.

If this won't help, please paste your code here - youtube embedding and your JS calls and I'll try to help.

EDIT

Try to use flash embedding like in Samsung docs.

As a movie parameter pass the src to YouTube API player:

<object type="application/x-shockwave-flash" id="playerObject">
  <param name="movie" value="http://www.youtube.com/apiplayer?&enablejsapi=1"></param>
  <param name="allowScriptAccess" value="always"></param>
  <param name="allowFullScreen" value="true"></param>
  <param name="wmode" value="transparent"></param>
</object>

And use this methods:

var ytPlayer = null;
function onYouTubePlayerReady() {
  ytPlayer = document.getElementById('playerObject');
  if (ytPlayer) {
    ytPlayer.addEventListener('onStateChange','onChange');
    ytPlayer.addEventListener('onError', 'onError');
    ytPlayer.cueVideoById('i4iDWXstrWY'); //load video for play http://www.youtube.com/watch?v=i4iDWXstrWY
  } else {
    alert("error");
  }
}
function onChange(newState) {
  //Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5)
  switch (newState) {
    case 5:
      ytPlayer.playVideo();
      break;
  }
function onError(errorCode) {
  alert(errorCode);
}

When the player is ready, the API will call the onYouTubePlayerReady callback function. I think that in your solution you are missing the cueVideoById method. As it is said in YT API doc

Plays the currently cued/loaded video.