Hey all So Im new here and I’d first like to introduce myself as it looks like I’m going to be here for a while :). My name is Mike and I am in school for game programming. I am very interested in flash and it’s capabilities and this seems like a great community for me to grow and hopefully one day give back!
That being said my first self project is to make a flash player like youtube (just not as good…obviously) Right now the player sort of works however I can’t seem to get the total length of the movie so I can have a scrub bar working or a fast forward button which just goes to the last frame of the movie. Here is my code… any help would be great!
flash.display.SimpleButton;
var nC: NetConnection = new NetConnection();
nC.connect( null );
var nS: NetStream = new NetStream( nC );
videoPlayer.attachNetStream( nS );
var url = "C:/Users/Cashin/Desktop/player/media/1.f4v";
nS.client = this;
nS.bufferTime = 5;
nS.play( url );
nS.addEventListener( NetStatusEvent.NET_STATUS, onNetStreamStatusEvent );
pauseBTN.visible = false;
function onNetStreamStatusEvent( e:NetStatusEvent ): void {
switch( e.info.code ) {
case "NetStream.Play.StreamNotFound":
trace("Video was not found...");
break;
case "NetStream.Play.Start":
trace("Video has started playing...");
break;
case "NetStream.Play.Stop":
nS.seek(2);
trace("Video has stopped playing...");
break;
case "NetStream.Buffer.Empty":
trace("Data is not being received fast enough for the buffer...");
nS.pause();
trace(nS.bytesTotal);
videoPlayer.addEventListener( Event.ENTER_FRAME, function() {
if ( nS.bufferLength >= nS.bufferTime || nS.bytesLoaded == nS.bytesTotal ) {
videoPlayer.removeEventListener( Event.ENTER_FRAME, arguments.callee );
nS.resume();
}
} );
break;
case "NetStream.Buffer.Full":
playBTN.addEventListener( 'mouseUp', playMovie );
reviewBTN.addEventListener( 'mouseUp', reviewMovie );
fastForwardBTN.addEventListener( 'mouseUp', fastForwardMovie );
trace("Buffer filled, video is good to go...");
break;
case "NetStream.Buffer.Flush":
trace("Video finished, buffer emptied...");
break;
case "NetStream.Seek.InvalidTime":
trace("Trying to seek to an invalid time");
break;
case "NetStream.Seek.Notify":
trace("Seek is finished");
break;
}
}
function reviewMovie( e: MouseEvent ) {
nS.play( url, 2 );
}
function fastForwardMovie( e: MouseEvent ) {
//trace();
//nS.seek( Stream.length );
}
function pauseMovie( e: MouseEvent ) {
nS.pause();
pauseBTN.removeEventListener( 'mouseUp', pauseMovie );
playBTN.addEventListener( 'mouseUp', playMovie );
pauseBTN.visible = false;
playBTN.visible = true;
}
function playMovie( e: MouseEvent ) {
nS.resume();
playBTN.removeEventListener( 'mouseUp', playMovie );
pauseBTN.addEventListener( 'mouseUp', pauseMovie );
pauseBTN.visible = true;
playBTN.visible = false;
}
/*function onMetaData(metadata:Object):void
{trace(meta.duration);
}*/
Thanks so much and cheers!!! Speak to yall soon