Solved

Vimeo player in Flex app

Posted on 2010-09-21
5
587 Views
Last Modified: 2013-11-11
Hi,

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

Thanks!
0
Comment
Question by:mrdumont
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:moagrius
ID: 33861560
are you attempting to load the actual Vimeo player in your app, or just the video itself?
0
 

Author Comment

by:mrdumont
ID: 33877771
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
 

Author Comment

by:mrdumont
ID: 34045148
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
 
LVL 19

Accepted Solution

by:
moagrius earned 500 total points
ID: 34048410
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now