I’m loading a .flv file with the NetStream object within a class. I’m trying to get the duration of the video through the onMetaData event but I can’t seem to take that information out of the function (if I try to access the data or trace the value I get undefined).
import mx.utils.Delegate;
import caurina.transitions.Tweener;
class PresentationSlideshow.VideoPlayer.VideoScaffold extends MovieClip {
private var _stageWidth:Number = Stage.width;
private var _stageHeight:Number = Stage.height;
private var _ncConnection:NetConnection;
private var _nsStream:NetStream;
private var _flv_mc:MovieClip;
private var _audio_sound:Sound;
private var _isPlaying:Boolean = true;
private var _isMuted:Boolean = false;
private var _videoDuration:Number = 0;
public function VideoScaffold(path:String, vWidth:Number, vHeight:Number){
buildScaffold(path, vWidth, vHeight);
_root.movieContainer._alpha = 100; //this needs to be replaced with proper fade in code
loadVideo(path);
}
private function buildScaffold(path:String, vWidth:Number, vHeight:Number){
// Create container for movie
var movieContainer:MovieClip = _root.createEmptyMovieClip("movieContainer", _root.getNextHighestDepth());
// Attach the video objct within the empty movie
movieContainer.attachMovie("theVideo", "videoContainer", this.getNextHighestDepth());
// Set the container so the video is in the exact middle of the screen
movieContainer.videoContainer._width = vWidth;
movieContainer.videoContainer._height = vHeight;
movieContainer._x = (_stageWidth/2) - (vWidth/2);
movieContainer._y = (_stageHeight/2) - (vHeight/2);
movieContainer.attachMovie("videoControls", "videoControls", movieContainer.getNextHighestDepth());
movieContainer.videoControls._x = (vWidth/2)-225;
movieContainer.videoControls._y = vHeight + 40;
// Makes everything invisible
movieContainer._alpha = 0;
}
private function loadVideo(path:String):Void{
// get the video connected properly
_ncConnection = new NetConnection();
_ncConnection.connect(null);
_nsStream = new NetStream(_ncConnection);
_root.movieContainer.videoContainer.vMovie.attachVideo(_nsStream);
_nsStream.play(path);
// Attach the sound from the video to a new movie clip
this.createEmptyMovieClip("flv_mc", this.getNextHighestDepth());
_flv_mc.attachAudio(_nsStream);
var _audio_sound:Sound = new Sound(_flv_mc);
// Get the duration of the video
[COLOR="Red"]_nsStream.onMetaData = function(obj:Object) {
_videoDuration = obj.duration;
trace(_videoDuration);
}[/COLOR]
// Mute Button code
var _isMuted:Boolean = false
_root.movieContainer.videoControls.volumeButton.onRelease = function(){
trace(_isMuted);
switch (_isMuted) {
case false :
trace("is false");
_audio_sound.setVolume(0);
_isMuted = true;
_root.movieContainer.videoControls.volumeButton.gotoAndStop("muted");
break;
case true :
trace("is true");
_audio_sound.setVolume(100);
_isMuted = false;
_root.movieContainer.videoControls.volumeButton.gotoAndStop("unMuted");
break;
}
}
// Scrubber codde
_root.movieContainer.videoControls.slider.onPress = function(){
this.startDrag(true, 75.5, 19.2, 375.5, 19.2);
trace(_videoDuration);
}
_root.movieContainer.videoControls.slider.onReleaseOutside = _root.movieContainer.videoControls.slider.onRelease = function(){
this.stopDrag();
}
// Button uses the Delegate class to force the button to play in proper scope
_root.movieContainer.videoControls.playPauseButton.onRelease = Delegate.create(this, playPauseEvent);
}
private function playPauseEvent():Void {
switch (_isPlaying) {
case true :
_nsStream.pause();
_isPlaying = false;
_root.movieContainer.videoControls.playPauseButton.gotoAndStop("playState")
break;
case false :
_nsStream.pause();
_isPlaying = true;
_root.movieContainer.videoControls.playPauseButton.gotoAndStop("pauseState")
}
}
}
I’m creating a video scrubber and I need the duration value to make it work. Any ideas?
–thanks