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=seGhTWE98DU&t=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;
videoplayer.playVideo(videoID);

}

The videoID get's passed into the function by the play Button, that
retrieves the videoID from the grid, that was selected.

Am I making something wrong, or why does my video only play the sound?
How can I place it in the videoDisplay component (canvas), so that it is
visible?

If anyone has a nice video player example, that has a scrub bar and a
play/pause/stop and volume controller, I would be very glad, if you
could let me know, where I might find this.

Thanks a lot in advance,

Pascal




--
John C. Bland II
Chief Geek
Katapult Media, Inc. - www.katapultmedia.com
---
Biz Blog - http://blogs.katapultmedia.com/jb2
Personal Blog - http://blog.blandfamilyonline.com
http://www.lifthimhigh.com - "Christian Products for Those Bold Enough to Wear Them"
Home of FMUG.az - http://www.gotoandstop.org
Home of AZCFUG - http://www.azcfug.org __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to