1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
var Youtube =
{
type: "youtube",
loaded: false,
pending: false,
playing: false,
player: null,
playerId: null,
timeout: null,
video: null,
width: "100%",
height: "100%",
getYtid: function (url)
{
if (! url) return
var ytid = url.substr(url.indexOf("v=")+2,11)
if (ytid.indexOf("&") !== -1)
ytid = ytid.substr(0, ytid.indexOf("&"))
if (ytid.indexOf("#") !== -1)
ytid = ytid.substr(0, ytid.indexOf("#"))
return ytid
},
play: function (video)
{
d.warn("YOUTUBE PLAY "+video.key)
if (video.error)
return Youtube.error()
if (Youtube.playing)
Youtube.stop()
Youtube.video = video
Youtube.playing = true
if (Youtube.ready)
{
d.warn("ORDERING VIDEO LOAD "+video.name)
Youtube.player.loadVideoById(video.name)
Youtube.pending = false
}
else
{
d.error("YOUTUBE PLAYER NOT READY")
Youtube.pending = true
}
},
toggle: function ()
{
if (Youtube.playing)
return Youtube.pause()
else
return Youtube.resume()
},
error: function (s)
{
Player.error("YOUTUBE "+s)
$("li#queue_"+Youtube.video.idx+" span.title").html("<i>This video cannot be embedded</i>")
setTimeout(Youtube.finish, 1000)
},
onStateChange: function (state)
{
Youtube.state = state
if (state === -1)
{
d.warn("YOUTUBE: UNSTARTED")
Youtube.playing = false
}
else if (state === 0)
{
d.warn("YOUTUBE: ENDED")
Youtube.playing = false
return Youtube.finish()
}
else if (state === 1)
{
d.warn("YOUTUBE: PLAYING")
Youtube.playing = true
if (! Youtube.loaded)
return Youtube.unload()
}
else if (state === 2)
{
d.warn("YOUTUBE: PAUSED")
Youtube.playing = false
}
else if (state === 3)
{
d.warn("YOUTUBE: BUFFERING")
}
else if (state === 5)
{
d.warn("YOUTUBE: CUED")
}
else
{
d.error("YOUTUBE: UNKNOWN")
}
},
onError: function (error)
{
var errorStr = 'UNKNOWN'
if (error === 2)
errorStr = "INVALID PARAMETER"
if (error === 100)
errorStr = "NOT FOUND"
if (error === 101 || error === 150)
errorStr = "EMBED FORBIDDEN"
Youtube.error(errorStr)
},
setVolume: function (vol)
{
Youtube.player.setVolume(vol)
},
pause: function ()
{
d.warn("PAUSED PLAYBACK")
Youtube.playing = false
Youtube.player.pauseVideo()
return true
},
resume: function ()
{
d.warn("RESUME PLAYBACK")
Youtube.playing = true
Youtube.player.playVideo()
return false
},
stop: function ()
{
d.warn("YOUTUBE STOP")
Youtube.player.stopVideo()
Youtube.playing = false
},
finish: function ()
{
d.warn("YOUTUBE FINISH")
Youtube.playing = false
Player.finish()
},
load: function ()
{
d.warn("LOADING YOUTUBE")
$("#ytscreen").css("z-index", 19)
Youtube.loaded = true
},
unload: function ()
{
d.warn("YOUTUBE UNLOADED")
$("#ytscreen").css("z-index", -3)
if (Youtube.player)
Youtube.player.stopVideo()
Youtube.playing = false
Youtube.loaded = false
Youtube.pending = false
},
init: function ()
{
d.warn("YOUTUBE INIT")
var params = { allowScriptAccess: "always", wmode: "opaque" }
var atts = { id: "ytscreen" }
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=ytscreen",
"ytscreen", Player.width, Player.height, "8", null, null, params, atts)
}
}
function onYouTubePlayerReady (playerId)
{
d.warn("YOUTUBE READY")
Youtube.player = document.getElementById(playerId)
Youtube.playerId = playerId
Youtube.player.addEventListener("onStateChange", "Youtube.onStateChange")
Youtube.player.addEventListener("onError", "Youtube.onError")
Youtube.ready = true
if (! Youtube.loaded)
return Youtube.unload()
if (Youtube.pending)
Youtube.player.loadVideoById(Youtube.video.name)
Youtube.pending = false
}
Player.register(Youtube)
|