Re: [flexcoders] VideoPlayer Example
You can view a sample I built right around the time Flex released so there may be other ways to do things. Ignore all of the graphic stuff. This is a very simple example and not even close to being a full video player. http://labs.katapultmedia.com/flex/VideoPlayer/Note:I just turned FMS on again. It will be turned off again soon but you can still View Source. On 11/3/06, Pascal Schrafl [EMAIL PROTECTED] wrote: Hi all, I'm trying to build a videoplayer, that gets some urls from an XML file and then can play those .flv, that are located at those urls. I looked at the Flex Manual and have used the NetConnection Example. Now as I plug the videoPlayer Component into my application, I suddenly only hear the sound, but don't see the video. I'm sure it is playing somewhere, just not there, where I want to to play. I have the following class, that I use: package youtube { import flash.display.Sprite; import flash.events.NetStatusEvent; import flash.events.SecurityErrorEvent; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; import flash.events.Event; import flash.display.StageScaleMode; // import flash.display.StageAlign; import flash.net.URLRequest; import flash.net.URLLoader; public class VideoPlayer extends Sprite { private var videoURL:String // = http://www.youtube.com/get_video.php?video_id=seGhTWE98DUt=OEgsToPDskJTX-7s6JV2QE3tijPcNMT6.flv ; private var connection:NetConnection; private var stream:NetStream; // variables for video url private var loader:URLLoader; private var videoID:String; public function VideoPlayer() { // stage.align = StageAlign.TOP_LEFT; // stage.scaleMode = StageScaleMode.NO_SCALE; trace(1. VideoPlayer instanziert) connection = new NetConnection(); trace(2. new Net Connection); // connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); trace(3. error handler eventListener); connection.connect(null); trace(4. connection(null)); } public function playVideo(myVideoID:String):void { trace(videoID received in Method: + myVideoID); // First, load the YouTube video page to get the 't' parameter. // See loadComplete() trace(playVideo aufgerufen) loader = new URLLoader(); loader.addEventListener(complete, loadComplete); loader.load(new URLRequest(http://www.youtube.com/watch?v= + myVideoID)); trace(5. url request: http://www.youtube.com/watch?v= + myVideoID); videoID = myVideoID; } private function loadComplete(event:Event):void { // Extract 't' parameter, pass it to get_video.php trace(6. loadComplete: + event); trace(videoID in loadComplete Function: + videoID); var t:String = String(loader.data).match(/t=[^]*/)[0]; trace(7. t String: + t); videoURL = http://www.youtube.com/get_video.php?video_id= + videoID + t + .flv; trace(8. videoURL got from Server: http://www.youtube.com/get_video.php?video_id= + videoID + t + .flv); connectStream(); } /* private function netStatusHandler(event:NetStatusEvent):void { switch (event.info.code) { case NetConnection.Connect.Success: trace(connectStream in netStatus Handler); connectStream(); break; case NetStream.Play.StreamNotFound: trace(Stream not found: + videoURL); break; } } */ private function securityErrorHandler(event:SecurityErrorEvent):void { trace(securityErrorHandler: + event); } private function connectStream():void { trace(connect Stream); var stream:NetStream = new NetStream(connection); // stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); stream.client = new CustomClient(); var video:Video = new Video(); // video.x = 1; // video.y = 1; video.height = 240; video.width = 320; // video.opaqueBackground = true; video.attachNetStream(stream); stream.play(videoURL); trace(videoURL final: + videoURL); addChild(video); } } } class CustomClient { public function onMetaData(info:Object):void { trace(metadata: duration= + info.duration + width= + info.width + height= + info.height + framerate= + info.framerate); } public
Re: [flexcoders] VideoPlayer Example
Hi Marcel, I didn't try that. But I will add this line of code to the application init function. I will post you my results. Best regards, Pascal Marcel Fahle wrote: Hey Pascal, without looking at your code (but the symptoms are familar to me ;)): did you gave the domain www.youtube.com http://www.youtube.com permission using Security.allowDomain()? Marcel -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
[flexcoders] VideoPlayer Example
Hi all, I'm trying to build a videoplayer, that gets some urls from an XML file and then can play those .flv, that are located at those urls. I looked at the Flex Manual and have used the NetConnection Example. Now as I plug the videoPlayer Component into my application, I suddenly only hear the sound, but don't see the video. I'm sure it is playing somewhere, just not there, where I want to to play. I have the following class, that I use: package youtube { import flash.display.Sprite; import flash.events.NetStatusEvent; import flash.events.SecurityErrorEvent; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; import flash.events.Event; import flash.display.StageScaleMode; // import flash.display.StageAlign; import flash.net.URLRequest; import flash.net.URLLoader; public class VideoPlayer extends Sprite { private var videoURL:String // = http://www.youtube.com/get_video.php?video_id=seGhTWE98DUt=OEgsToPDskJTX-7s6JV2QE3tijPcNMT6.flv;; private var connection:NetConnection; private var stream:NetStream; // variables for video url private var loader:URLLoader; private var videoID:String; public function VideoPlayer() { // stage.align = StageAlign.TOP_LEFT; // stage.scaleMode = StageScaleMode.NO_SCALE; trace(1. VideoPlayer instanziert) connection = new NetConnection(); trace(2. new Net Connection); // connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); trace(3. error handler eventListener); connection.connect(null); trace(4. connection(null)); } public function playVideo(myVideoID:String):void { trace(videoID received in Method: + myVideoID); // First, load the YouTube video page to get the 't' parameter. // See loadComplete() trace(playVideo aufgerufen) loader = new URLLoader(); loader.addEventListener(complete, loadComplete); loader.load(new URLRequest(http://www.youtube.com/watch?v=; + myVideoID)); trace(5. url request: http://www.youtube.com/watch?v=; + myVideoID); videoID = myVideoID; } private function loadComplete(event:Event):void { // Extract 't' parameter, pass it to get_video.php trace(6. loadComplete: + event); trace(videoID in loadComplete Function: + videoID); var t:String = String(loader.data).match(/t=[^]*/)[0]; trace(7. t String: + t); videoURL = http://www.youtube.com/get_video.php?video_id=; + videoID + t + .flv; trace(8. videoURL got from Server: http://www.youtube.com/get_video.php?video_id=; + videoID + t + .flv); connectStream(); } /* private function netStatusHandler(event:NetStatusEvent):void { switch (event.info.code) { case NetConnection.Connect.Success: trace(connectStream in netStatus Handler); connectStream(); break; case NetStream.Play.StreamNotFound: trace(Stream not found: + videoURL); break; } } */ private function securityErrorHandler(event:SecurityErrorEvent):void { trace(securityErrorHandler: + event); } private function connectStream():void { trace(connect Stream); var stream:NetStream = new NetStream(connection); // stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); stream.client = new CustomClient(); var video:Video = new Video(); // video.x = 1; // video.y = 1; video.height = 240; video.width = 320; // video.opaqueBackground = true; video.attachNetStream(stream); stream.play(videoURL); trace(videoURL final: + videoURL); addChild(video); } } } class CustomClient { public function onMetaData(info:Object):void { trace(metadata: duration= + info.duration + width= + info.width + height= + info.height + framerate= + info.framerate); } public function onCuePoint(info:Object):void { trace(cuepoint: time= + info.time + name= + info.name + type= + info.type); } } In my videoDisplay component (it's a canvas) I use this code, to start the video: import youtube.VideoPlayer; public function play(videoID:String):void { var videoplayer:VideoPlayer = new VideoPlayer(); videoplayer.x = 0; videoplayer.y = 0;