Welcome to WebmasterWorld Guest from 54.147.20.131

Forum Moderators: open

Message Too Old, No Replies

Flash 8 FLV preloader

Flash 8 FLV preloader

     

beaudettee

2:52 am on Sep 4, 2007 (gmt 0)

5+ Year Member



Hi All:

I was "handed" a 9mb flv file (good quality video and audio) that I need to preload. I created a new fla, imported the flv to the stage and had Flash create a player (skin) for me during the Import process. Everything looks great. I publish and come up with an swf file that basically encases the player within it and calls the flv to play. The problem is I cannot seem to generate a preloader within the swf that will call and load the flv. I tried using the flash help files version but to no avail. It never seems to recognize the flv so the dynamic text counter does nothing. The help preloader works fine if calling a single flv file however not from within the swf with the player. So..

1. final swf with no player controls and the preloader works (calls and plays flv)
2. final swf with player controls and no preloader works (calls and plays flv
3. final swf with player and calling preloader action script fails miserably.

What am I doing wrong? Any help would be greatly appreciated. Thanks!

Eric B

alexdunae

4:40 pm on Sep 6, 2007 (gmt 0)

5+ Year Member



Here's the loading code from a flash video player I wrote a while back--it might help get you started.All the heavy work is done by the
NetStream()
class.


var nc:NetConnection;
var ns:NetStream;

function loadVideo(url:String, autoStart:Boolean) {
// begin preloading video and set up the UI
var media_url:String = url;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.setBufferTime(10);

player_vid.attachVideo(ns);
ns.play(media_url);
if(autoStart) {
showPauseControls();
} else {
ns.pause();
showPlayControls();
}

var buffer_interval:Number = setInterval(checkBufferTime, 100, ns);

function checkBufferTime(ns:NetStream):Void {
_root.preload_txt._visible = true;
var buffer:Number = Math.round(ns.bufferLength/ns.bufferTime * 100);
_root.preload_txt.text= "Buffering video: " + buffer + "%";
if (buffer >= 100) {
clearInterval(buffer_interval);
_root.preload_txt._visible = false;
}
}

progress_mc.loadbar_mc.onRelease = function() {
// user can click on loadbar_mc and to select cue point in media file
var cue_percentage:Number = calculate_cue_percentage();
var cue_seconds:Number = (cue_percentage / 100) * (video_duration);
ns.seek(cue_seconds);
ns.pause(false);
showPauseControls();
buffer_interval = setInterval(checkBufferTime, 100, ns);
}

rewind_btn.onRelease = function() {
ns.seek(0);
}

play_btn.onRelease = function() {
ns.pause(false);
showPauseControls();
}

pause_btn.onRelease = function() {
ns.pause(true);
showPlayControls();
}

var video_duration:Number;
var video_w:Number;
var video_h:Number;

ns.onMetaData = function(meta) {
video_duration = meta.duration;
video_w = meta.width;
video_h = meta.height;
positionVideoPlayer();
};

function positionVideoPlayer():Void {
// resize video if it is larger than the viewport
_root.player_vid._width = (video_w > viewport_w? viewport_w : video_w);
_root.player_vid._height = (video_h > viewport_h? viewport_h : video_h);

// center the video
_root.player_vid._x = (viewport_w - _root.player_vid._width) / 2;
_root.player_vid._y = (viewport_h - _root.player_vid._height) / 2;
}

time_interval = setInterval(checkVideoTime, 500, ns);

function checkVideoTime(ns:NetStream){
update_time(ns.time, video_duration);
}

loaded_interval = setInterval(checkVideoBytesLoaded, 500, ns);

function checkVideoBytesLoaded(ns:NetStream) {
var loaded:Number = Math.round(ns.bytesLoaded / ns.bytesTotal * 100);
update_load_progress(loaded);
if (loaded >= 100) {
clearInterval(loaded_interval);
}
}
}

function update_time(current:Number, duration:Number):Void {
var minutes:Number = Math.floor(current/60);
var hours:Number = Math.floor(minutes/60);
var seconds = Math.floor(current%60);

var minutes_txt:String = (minutes < 10)?"0" + minutes : minutes;
var seconds_txt:String = (seconds < 10)?"0" + seconds : seconds;

time_txt.text = hours + ":" + minutes_txt + ":" + seconds_txt;
progress_mc.timebar_mc._xscale = (current / duration * 100);
}

function update_load_progress(percent:Number):Void {
progress_mc.loadbar_mc._xscale = percent;
}

beaudettee

3:08 pm on Sep 13, 2007 (gmt 0)

5+ Year Member



Thanks Alex. I'll give it a try.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month