Solved

Vimeo player in Flex app

Posted on 2010-09-21
5
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

724 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