Solved

Vimeo player in Flex app

Posted on 2010-09-21
5
596 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

809 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