概括
我的 Flex/AS3 应用程序中有一个 Youtube API 无铬播放器。有时我需要播放器连续播放来自 Youtube 的电影(不间断)。
问题
在玩了 12 小时或更长时间后,由第一个播放器初始化请求生成的 API 令牌即将过期。
http://www.youtube.com/apiplayer?version=3&modestbranding=1&autoplay=0
这里的问题是令牌过期后再次调用的API调用loadVideoById无法开始播放视频,因为令牌没有自动更新。
在播放我们的播放列表(通过调用loadVideoById播放每个项目)大约4-5 小时或更长时间后,视频有时会开始播放并突然卡住。虽然没有派发错误事件。
已知解决方案
因此,对于第一个问题,解决方案是每 12 小时更新一次令牌,方法是卸载播放器并使用 API 调用再次加载它:
http://www.youtube.com/apiplayer?version=3&modestbranding=1&autoplay=0
对于第二个问题,没有想法。需要你的帮助。
相关源代码
private function CreateYoutubePlayerSWF():void {
...
theYoutubeLoader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
theYoutubeLoader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3&modestbranding=1&autoplay=0"));
...
}
private function PlayPendingVideo():void {
...
theYoutubePlayer.loadVideoById(videoWaitingToPlayInfo.videoWaitingToPlay);
...
}
请求和响应
当播放器停止播放时,这就是我在提琴手中得到的:
"request": {
"method": "GET",
"url": "http://www.youtube.com/get_video?cpn=Lj5HaLu7MzS5kG-T&fmt=35&splay=1&t=vjVQa1PpcFNwMVrYUDFOTTG-7co1uJFo3oyrB-qoP_k=&video_id=j-vJJSqw5Q4&eurl=http%3A%2F%2Fwatchitoo.com%2Fiframe.php%3Fid%3Dwwa-154%26scale%3Dfalse%26layout%3D14&asv=3&el=embedded&ps=chromeless&ptk=youtube_none&noflv=1",
...
"queryString": [
{
"name": "cpn",
"value": "Lj5HaLu7MzS5kG-T"
},
{
"name": "fmt",
"value": "35"
},
{
"name": "splay",
"value": "1"
},
{
"name": "t",
"value": "vjVQa1PpcFNwMVrYUDFOTTG-7co1uJFo3oyrB-qoP_k"
},
{
"name": "video_id",
"value": "j-vJJSqw5Q4"
},
{
"name": "eurl",
"value": "http%3A%2F%2Fwatchitoo.com%2Fiframe.php%3Fid%3Dwwa-154%26scale%3Dfalse%26layout%3D14"
},
{
"name": "asv",
"value": "3"
},
{
"name": "el",
"value": "embedded"
},
{
"name": "ps",
"value": "chromeless"
},
{
"name": "ptk",
"value": "youtube_none"
},
{
"name": "noflv",
"value": "1"
}
"response": {
"status": 410,
"statusText": "Gone",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Date",
"value": "Wed, 26 Jun 2013 16:32:37 GMT"
},
{
"name": "X-Content-Type-Options",
"value": "nosniff"
},
{
"name": "Server",
"value": "Apache"
},
{
"name": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"name": "Content-Type",
"value": "video/x-flv"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Content-Length",
"value": "0"
},
{
"name": "Expires",
"value": "Tue, 27 Apr 1971 19:44:06 EST"
}