public YouTubePlayer( string TargetContent = "http://www.youtube.com/apiplayer?version=3", int DefaultWidth = 1280, int DefaultHeight = 720, string DefaultVideo = "Z__-3BbPq6g", string suggestedQuality = "hd720", Action yield_init = null ) { var ldr = new Loader(); this.Loader = ldr; var urlReq = new URLRequest(TargetContent); var ctx_app = ApplicationDomain.currentDomain; var ctx_sec = SecurityDomain.currentDomain; // http://www.youtube.com/crossdomain.xml ctx_app = null; ctx_sec = null; // http://www.zedia.net/2010/using-the-actionscript-3-youtube-api/ bool once = false; #region onReady Action<Event> onReady = e => { if (once) return; once = true; #if JSC_FEATURE_dynamic dynamic player = ldr.content; player.setSize(160, 120); #endif ldr.content.setSize(DefaultWidth, DefaultHeight); pauseVideo = delegate { ldr.content.pauseVideo(); }; loadVideoById = x => { CurrentVideoId = x; ldr.content.loadVideoById(x, suggestedQuality: suggestedQuality); }; loadVideoById(DefaultVideo); if (yield_init != null) { yield_init(); yield_init = null; } }; #endregion var PreviousCurrentState = YouTubePlayerState.unknown; var CurrentState = YouTubePlayerState.unknown; DefaultScene = this["default", 0, 1000]; var CurrentScene = DefaultScene; Action CurrentSceneDone = delegate { }; #region onStateChange Action<Event> onStateChange = e => { PreviousCurrentState = CurrentState; CurrentState = e.get_data_as_YouTubePlayerState(); if (PreviousCurrentState != CurrentState) { if (CurrentState == YouTubePlayerState.playing) { // notify other scenes of delinking? if (this.Playing != null) this.Playing(SceneTranslate(CurrentScene)); this.ReferencedScenes.WithEach( k => { k.RaiseLinkDenotification(); } ); } else { if (this.NotPlaying != null) this.NotPlaying(SceneTranslate(CurrentScene)); } if (CurrentState == YouTubePlayerState.paused) { if (this.Paused != null) this.Paused(SceneTranslate(CurrentScene)); } } }; #endregion var TimeToPause = 0.4; var t = new Timer(1000 / 100); var PlaySceneCounter = 0; t.timer += delegate { if (ldr.content == null) return; if (CurrentState == YouTubePlayerState.playing) { var time = ldr.content.getCurrentTime(); var time_index = (int)time; var duration = ldr.content.getDuration(); var playall = CurrentScene.end > duration; // flag4 = ((double0 < (double2 - 500)) == 0); // 1 second is 1.0!! :) var notending = time < (duration - 0.500); //var xending = time >= (duration - 500); var ending = !notending; // ReferenceError: Error #1069: Property getDuration not found on flash.display.Loader and there is no default value. var m = new { PlaySceneCounter, time, time_index, CurrentScene.end, duration, playall, ending }.ToString(); if (StatusToClients != null) StatusToClients(m); // phone activated if (playall) { if (ending) { ldr.content.pauseVideo(); CurrentSceneDone(); } } else if (time >= (TimeToPause)) { ldr.content.pauseVideo(); CurrentSceneDone(); } } }; t.start(); #region PlayScene this.PlayScene = (e, Done) => { PlaySceneCounter++; //if (e.end == 0) // e.end = ldr.content.getDuration() - 1000; CurrentScene = e; CurrentSceneDone = Done; TimeToPause = e.end; ldr.content.seekTo(e.start); ldr.content.playVideo(); }; #endregion ldr.contentLoaderInfo.ioError += delegate { }; ldr.contentLoaderInfo.init += delegate { ldr.content.addEventListener("onReady", onReady.ToFunction(), false, 0, false); ldr.content.addEventListener("onStateChange", onStateChange.ToFunction(), false, 0, false); }; var ctx = new LoaderContext(true, ctx_app, ctx_sec); ldr.load(urlReq, ctx); this.Scenes = new SceneSequenzer { Owner = this }; }
public MySprite1() { // http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html InternalLoadTargetContent = TargetContent => { this.OrphanizeChildren(); // read more: http://www.senocular.com/flash/tutorials/contentdomains/ Security.allowDomain("*"); Security.allowInsecureDomain("*"); //Security.loadPolicyFile("http://www.youtube.com/crossdomain.xml"); // http://code.google.com/apis/youtube/flash_api_reference.html // http://code.google.com/p/gdata-samples/source/browse/trunk/ytplayer/actionscript3/com/google/youtube/examples/AS3Player.as var ldr = new Loader(); var urlReq = new URLRequest(TargetContent); var ctx_app = ApplicationDomain.currentDomain; var ctx_sec = SecurityDomain.currentDomain; if (TargetContent.StartsWith("http://www.youtube.com/")) { // http://www.youtube.com/crossdomain.xml ctx_app = null; ctx_sec = null; // http://www.zedia.net/2010/using-the-actionscript-3-youtube-api/ DoplayVideo = delegate { ldr.content.playVideo(); }; DoloadVideoById = (id, s, q) => { ldr.content.loadVideoById(id, s, q); }; Action<Event> onReady = e => { if (VideoPlayerReady != null) VideoPlayerReady(); #if JSC_FEATURE_dynamic dynamic player = ldr.content; player.setSize(160, 120); #endif ldr.content.setSize(160, 120); }; ldr.contentLoaderInfo.init += delegate { ldr.content.addEventListener("onReady", onReady.ToFunction(), false, 0, false); }; } ldr.contentLoaderInfo.complete += delegate { if (Ready != null) Ready(); }; //ldr.mouseChildren = false; var ctx = new LoaderContext(true, ctx_app, ctx_sec); ldr.load(urlReq, ctx); var sprite2 = new Sprite { z = 0.001 }.AttachTo(this); sprite2.graphics.drawRect(0, 0, 100, 100); var t = new Timer(1000 / 60); t.timer += delegate { var x = sprite2.x; var y = sprite2.y; sprite2.transform.matrix3D.appendTranslation(-x, -y, 0); sprite2.transform.matrix3D.appendRotation(0.01, Vector3D.Y_AXIS); sprite2.transform.matrix3D.appendRotation(0.02, Vector3D.X_AXIS); sprite2.transform.matrix3D.appendTranslation(x, y, 0); }; t.start(); DoClean = delegate { ldr.content.GetChildren().Where(k => k.GetType().Name == "InfoPanel").ToArray().WithEach( k => k.Orphanize() ); }; ldr.AttachTo(sprite2); var Inspect = default(Action<DisplayObject, XElement>); Inspect = (Target, Journal) => { var SourceType = Target.GetType(); var n = new XElement(SourceType.Name); n.Add(new XAttribute("Namespace", SourceType.Namespace)); SourceType.BaseType.With( BaseType => n.Add(new XAttribute("BaseType", BaseType.FullName)) ); Journal.Add(n); (Target as DisplayObjectContainer).With( Container => { for (int i = 0; i < Container.numChildren; i++) { Inspect(Container.getChildAt(i), n); } } ); }; DoInspect = delegate { var doc = new XElement("Inspection"); // SecurityError: Error #2121: Security sandbox violation: Loader.content: http://localhost:26925/assets/LoadExternalFlashComponent.Application/LoadExternalFlashComponent.Components.MySprite1.swf cannot access http://sketch.odopod.com/flash/OdoSketch.swf?sketchURL=/sketches/231498.xml&userURL=/users/21416&bgURL=/images/bigbg.jpg&mode=embed. This may be worked around by calling Security.allowDomain. // at flash.display::Loader/get content() try { Inspect(ldr.content, doc); } catch (Exception exc) { var n = new XElement("error", exc.Message); doc.Add(n); } if (Inspecting != null) Inspecting(doc); }; }; LoadTargetContent(); }
/// <summary> /// Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into an object that is a child of this Loader object. /// </summary> public void load(URLRequest request, LoaderContext context) { }
/// <summary> /// Loads from binary data stored in a ByteArray object. /// </summary> public void loadBytes(ByteArray bytes, LoaderContext context) { }
public MySprite1() { // http://apiwiki.justin.tv/mediawiki/index.php/Live_Video_SWF_Documentation Security.allowDomain("*"); Security.allowInsecureDomain("*"); // http://apiwiki.justin.tv/mediawiki/index.php/Live_Video_SWF_Documentation //var TargetContent = "http://www.justin.tv/widgets/live_api_player.swf?video_height=480&video_width=640&consumer_key=YOUR_API_KEY"; var TargetContent = "http://www.justin.tv/widgets/live_api_player.swf?video_height=480&video_width=640"; var ldr = new Loader(); var urlReq = new URLRequest(TargetContent); var ctx_app = ApplicationDomain.currentDomain; var ctx_sec = SecurityDomain.currentDomain; ctx_sec = null; ctx_app = null; __api_play_live = delegate { }; ldr.contentLoaderInfo.complete += delegate { __api_play_live = channel => { ldr.content.api_play_live(channel); }; __api_play_live("nitro301"); //(ldr.content as dynamic).api.play_live("apidemo"); }; var ctx = new LoaderContext(true, ctx_app, ctx_sec); sprite2 = new Sprite { z = 0.02 }.AttachTo(this); sprite2.mouseChildren = false; ldr.AttachTo(sprite2); var t = new Timer(1000 / 60); t.timer += delegate { var x = sprite2.x; var y = sprite2.y; sprite2.transform.matrix3D.appendTranslation(-x, -y, 0); sprite2.transform.matrix3D.appendRotation(0.01, Vector3D.Y_AXIS); sprite2.transform.matrix3D.appendRotation(0.02, Vector3D.X_AXIS); sprite2.transform.matrix3D.appendTranslation(x, y, 0); }; t.start(); try { ldr.load(urlReq, ctx); } catch { } }