?
Solved

Vimeo player in Flex app

Posted on 2010-09-21
5
Medium Priority
?
614 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 2000 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

Industry Leaders: 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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
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): …
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…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 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