[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 631
  • Last Modified:

Vimeo player in Flex app

Hi,

I'm having trouble embedding Vimeo videos in my Flex based application. Any help will be greatly appreciated.

Thanks!
0
mrdumont
Asked:
mrdumont
  • 2
  • 2
1 Solution
 
moagriusCommented:
are you attempting to load the actual Vimeo player in your app, or just the video itself?
0
 
mrdumontAuthor Commented:
Hi - either way would be fine, actually. I have a player skin i can use but am happy with the standard Vimeo player. The important point is that i need to embed several videos in a single Flex app.

Any help will be greatly appreciated!
0
 
mrdumontAuthor Commented:
Hi - sorry, too many issues going on at the same time. Would like to keep this open for a bit longer to see if moagrius has a helpful comment - thanks!
0
 
moagriusCommented:
the short answer is to use the Video object.  you can create an instance (or multiple instances) of the Video object and add it to the display list, and use the load() method to play and FLV file (or other file types with certain restrictions).  this would allow you to control it with whatever skin you wanted.

in theory, you could use a Loader object to grab the player itself, but that might be bumpy - there may be security issues trying to load directly from Vimeo, and interacting with it might be difficult.

i'll attach a very basic class you can use to simplify instancing Videos.  usage is as simple as:

var vid:FLV = new FLV("path/to/your/video.flv");
whatever.addChild(vid);

... or ...

var vid:FLV = new FLV();
vid.load("path/to/your/video.flv");
whatever.addChild(vid);

i put the attached snippet together a long time ago (years), and it uses a few less-than-best-practices (the string cases and event types should probably be consts; the events should probably be fully-featured custom event class instances; etc).

you'd obviously want to either extend it (or more likely rewrite it entirely) to use your own skin and controls, but this might help get you started.

The Video object acts a little differently from most other objects in AS3 - it uses meta data callbacks instead of event dispatches/listeners for unknown reasons, and requires some odd configurations of the NetStream object used to supply it with information.

anyways, hth, gl
package {

	import flash.events.AsyncErrorEvent;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.media.Video;
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	
	public class FLV extends Video {
		
		private var stream:NetStream;
		private var conn:NetConnection;
		
		private var _url:String;
		
		private const ONDATA:Event = new Event("onData");
		private const ONERROR:Event = new Event("ioError");
		private const ONOPEN:Event = new Event("open");
		private const ONPLAY:Event = new Event("play");
		private const ONDONE:Event = new Event("done");
		
		public function FLV(url:String = ""):void {
			if (url) load(url);
		}
		public function pause():void{
            stream.pause();
        }
        public function resume():void{
            stream.resume();
        }
		public function seek(offset:Number):void {
			stream.seek(offset);
		}
		public function load(url:String):void {
			_url = url;
			close();
			conn = new NetConnection();
			conn.addEventListener("netStatus", netStatusHandler);
			conn.connect(null);
		}
		private function netStatusHandler(event:NetStatusEvent):void {
			switch (event.info.code) {
				case "NetConnection.Connect.Success":
					connectStream();
					dispatchEvent(ONOPEN);
					break;
				case "NetStream.Play.StreamNotFound":
					dispatchEvent(ONERROR);
					break;
				case "NetStream.Play.Stop":
					dispatchEvent(ONDONE);
					break;
			}
		}
		private function connectStream():void{
			stream = new NetStream(conn);
			stream.client = this;
			stream.addEventListener("asyncError", empty);
			stream.addEventListener("netStatus", netStatusHandler);
			stream.play(_url);
			dispatchEvent(ONPLAY);
			attachNetStream(stream);			
		}
		public function close():void {
			if (stream) {
				if (stream.hasEventListener("asyncError")) {
					stream.removeEventListener("asyncError", empty);
				}
				if (stream.hasEventListener("netStatus")) {
					stream.removeEventListener("netStatus", netStatusHandler);
				}
				try{
					stream.close();
				} catch (e) { };
				stream = null;
			}
			if (conn) {
				if(conn.hasEventListener("netStatus")) {
					conn.removeEventListener("netStatus", netStatusHandler);
				}
				try {
					conn.close();
				} catch (e) { };
				conn = null;
			}
			clear();
		}
		public function onMetaData(meta:Object):void {
			if (meta.height != null && meta.width != null) {
				height = meta.height;
				width = meta.width;
			}
			dispatchEvent(ONDATA);
		}
		private function empty(event:Event):void {}
	}
}

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now