2 function embedYoutubeVideo(id, _username, _podcast_url, _episode_url) {
4 var params = { allowScriptAccess: "always" };
5 var atts = { id: "ytplayer" };
7 // store global variables for onytplayerStateChange
9 podcast_url = _podcast_url;
10 episode_url = _episode_url;
11 already_played = false;
13 swfobject.embedSWF("http://www.youtube.com/v/" + id + "?enablejsapi=1&playerapiid=ytplayer",
14 "ytapiplayer", "425", "356", "8", null, null, params, atts);
18 function onYouTubePlayerReady(playerId) {
19 player = document.getElementById("ytplayer");
20 player.addEventListener("onStateChange", "onytplayerStateChange");
23 function onytplayerStateChange(newState) {
25 if ((newState == 1) && !already_played)
27 var str = JSON.stringify([{"podcast": podcast_url, "episode": episode_url, "action": "play"}])
28 $.post('/api/1/episodes/' + username + '.json', str);
29 already_played = true;