Macromedia Flex Macromedia Flex
Progressively Downloaded Video Player
  Home

Feb 19, 2008 - Progressively Downloaded Video Player
Useful when a streaming media server is unavailable

Here is some useful code to utilize when you don't have a streaming media server available..


private var _stream:NetStream;
private var _video:Video;
private var _playbackTime:TextField;
private var _duration:uint;

/* Functions */

private function stopVideo(event:Event):void {
Common.messageBox("Stop Video", "Stop Video");

if (_stream) {
_stream.close();
}
}

private function loadVideo():void {
var _url:String = "assets/videos/" + data + ".flv";

_video = new Video(160, 120);
_playbackTime = new TextField();
_playbackTime.autoSize = TextFieldAutoSize.LEFT;
_playbackTime.y = 120;
_playbackTime.text = "test";
_duration = 0;
var connection:NetConnection = new NetConnection();
connection.connect(null);
_stream = new NetStream(connection);
_stream.play(_url);
var client:Object = new Object();
client.onMetaData = onMetaData;
_stream.client = client;
_video.attachNetStream(_stream);

addEventListener(Event.ENTER_FRAME, onEnterFrame);
_video.height = 350;
_video.width = 550;

myVid.addChild(_video);
}

private function onMetaData(data:Object):void {
_duration = data.duration;
}

private function onEnterFrame(event:Event):void {
if(_duration > 0 && _stream.time > 0) {
_playbackTime.text = Math.round(_stream.time) + " / " +
Math.round(_duration);
}
}

/* MXML */












Billy Blackerby
bblackerby@tci-usa.com
http://www.tci-usa.com

File Details
Created On Feb, 19, 2008 by Billy Blackerby
Last Modified On Feb, 19, 2008 by Billy Blackerby
Group: Tips and Articles
Flex Versions: 2.0
Category: General
Type: Tip
Difficulty: Intermediate
Keywords: Video, VideoDisplay, Progressive, Streaming