2012.03.09 | mucho
こんばんはmuchoです。
USTREAMをFlash内に読み込もうとして、あれこれやってみたのでメモ。
下記のページを参考にしました。
Flash Client API Documentation (AsDoc)
USTREAM Flash Client APIの使い方
Flash : Ustream Flash Client APIを使ってみる - SWFなカスタムパネルで中継を再生
/*
ちょっと苦しんだのが、再生動画のオリジナルサイズを取得する方法
viewer.channel.streamRect
に格納されるみたいです。
再生開始時のイベントもうまく取れませんでした。
viewer.channel.addEventListener("found", onStart);
viewer.channel.addEventListener("createStream", onStart);
このどちらもviewer.channel.streamRect取得できず、
また表示のタイミングともちょっとズレがあるような?
そこはいい解決法が見つからず悲しい力技になってしまいました。
今後の課題です。
*/
public function main():void
{
getRsl();
visible = false;
}
private function getRsl():void
{
Security.allowDomain("*");
Security.allowInsecureDomain("*");
viewerLoader = new Loader();
viewerLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onRslLoad);
this.addChild(viewerLoader);
var applicationDomain:ApplicationDomain = ApplicationDomain.currentDomain;
var loaderContext:LoaderContext = new LoaderContext();
var request:URLRequest = new URLRequest("http://www.ustream.tv/flash/viewer.rsl.swf");
loaderContext.applicationDomain = applicationDomain;
viewerLoader.load(request, loaderContext);
}
private function onRslLoad(e:Event):void
{
var logicClass:Class = viewerLoader.contentLoaderInfo.applicationDomain.getDefinition("tv.ustream.viewer.logic.Logic") as Class;
viewer = new logicClass();
viewer.volume = 0;
this.addChild(viewer.display);
playChannel(id);
}
private function playChannel(id:String = null):void
{
var channelId:String = id;
if(id == null) {
id = default_channelID;
}
viewer.createChannel(id);
addEventListener(Event.ENTER_FRAME, onStart);
viewer.playing = true;
}
private function onStart(e:Event):void
{
if (!viewer.channel.streamRect) return;
e.target.removeEventListener(e.type, arguments.callee);
var vw:Number = viewer.channel.streamRect.width;
var vh:Number = viewer.channel.streamRect.height;
viewer.volume = vol;
viewer.display.x = 0;
viewer.display.y = 0;
viewer.display.width = viewer_width;
viewer.display.height = viewer_height = viewer_width * (vh / vw);
visible = true;
}

