Actually I don't understand what u said. I m new in Red5 and flash action
scripting. As I have given my code below again would anybody tell me where
might be the prob in my code?

import mx.utils.Delegate;

// hook up adhock listener for Xray events if the user doesn't have the xray
interface
//import com.blitzagency.xray.Xray;

var pauseStatus:Number;
pauseStatus = 0;
var videoStatus:Number;
videoStatus = 0;
//var total = 0;
//var loadedTime = 0;
var seekTo = 0;

//var startPosition = this.seekButton._x;
var fileName= "";

if(this.timePassed.text=="")
   this.timePassed.text = "0";

init();

function init()
{
   Xray.xrayTrace.addEventListener("onTrace", this);
   //mydgrid.setStyle("borderStyle", "none");
   mydgrid.setStyle("backgroundColor", 0xF3F0FB);
   mydgrid.setStyle("fontfamily", "Arial Rounded MT Bold");
   mydgrid.setStyle("fontSize", 12);
   mydgrid.setStyle("color", 0x333333);
   mydgrid.setStyle("embedfonts", true);
   mydgrid.setStyle("shadowColor", 0xBE9EDE);
   mydgrid.setStyle("borderCapColor", 0xBE9EDE);
   mydgrid.setStyle("shadowCapColor", 0xBE9EDE);


}

function onTrace(traceInfo):Void
{

   info.maxScroll;
}

// FCS connectio and shared Object
var nc:NetConnection;
var ns:NetStream = null;

// initial width and height
var vidWidth = this.videoContainer._width;
var vidHeight = this.videoContainer._height;

var lowBufferTime = "2";
var highBufferTime = "15";

function connect():Boolean
{
   this.nc = new NetConnection();
   this.nc.onStatus = Delegate.create(this, this.ncOnStatus);

   var connected:Boolean = this.nc.connect(this.rtmpURI.text);
   tt("connected?", connected);

   //light.gotoAndStop(2);
   return connected;
}

// disconnect from the fcs server
function disconnect()
{
   this.nc.close();
   stopWatchStream();
   //this.txtName.text = "Disconnected ";
   tt("disconnected");
}

// status for the netconnection
function ncOnStatus(obj:Object):Void
{
   //tt("NetConnection.onStatus", obj);

   if(obj.code == "NetConnection.Connect.Success")
   {
       this.txtName.text = "Connected";
       tt("catchVideos", catchVideos);
       catchVideos();
       //if(this.txtVideoName.text!=""){
       fileName = "Spiderman3_trailer_300_1";
       playMovie(fileName);
       //}
   }else if(obj.code == "NetConnection.Connect.Closed"){
       tt("Now Disconnected");
       this.txtName.text = "Disconnected ";
       //this.totalDuration.text =
       connect();
       catchVideos();
       //if(this.txtVideoName.text!=""){
       fileName = "Spiderman3_trailer_300_1";
       reloadMovie(fileName);
       //}
   }
}

// setup the netstream object
function initNetStream()
{

   this.ns = new NetStream(this.nc);
   this.ns.onStatus = Delegate.create(this, this.nsOnStatus);
   ns.setBufferTime(lowBufferTime);
   this.ns.onMetaData = Delegate.create(this, this.onMetaData);
   //pauseStatus = 0;
   //this.txtName.text = "";


}

function onMetaData(obj:Object):Void
{
   tt("metaData", obj);
   this.totalDuration.text = Math.round(obj.duration);
   tt(this.totalDuration.text);
   //frameRate.text = obj.framerate;
   //widthHeight.text = obj.width + "x" + obj.height;
}

// status for the netstream object
function nsOnStatus(obj:Object):Void
{
   tt("NetStream.onStatus", obj);

   if(this.totalDuration.text!=""){
   this.totalVal.text = this.totalDuration.text;

   }
       //tt("Total Rec: "+this.totalVal.text);


   if(obj.code == "NetStream.Buffer.Full")
   {
       snow._visible = false;
       startWatchStream();
       //if(this.totalDuration.text!="")


   }else if(obj.code == "NetStream.Buffer.Empty")
   {
       stopWatchStream();


   }else if (obj.code == "NetStream.Unpause.Notify"){
           this.txtName.text = "Buffering...";
   }
}
//Code Added Bu Mishu on test
function statusBar(){
       this.mcPosition._width = (Math.round(this.ns.time)*
this.mcProgressBar._width )/ this.totalDuration.text;
       //tt((Math.round(this.ns.time)* mcProgressBar._width )/
this.totalDuration.text);
       if(this.txtName.text == "Finished"){
           this.mcPosition._width = this.mcProgressBar._width;
           }

       //tt(this.seekButton._x);
       //tt(startPosition);
       //tt(this.mcProgressBar._width)
       /*
       if(this.seekButton._x >= (startPosition+this.mcProgressBar._width)){
           this.seekButton._x = this.seekButton._x - this.seekButton._width
;
           }
       else{
           this.seekButton._x = startPosition + this.mcPosition._width;
       }
       */
}



function startWatchStream()
{
   ns.setBufferTime(highBufferTime);
   //var fName = mydgrid.selectedItem.name
   var fName = fileName;
   this.txtName.text = "Playing: " + fName;

   this.onEnterFrame = function()
   {
       //tt(this.totalDuration.text);
       //tt(this.ns.time);

       if(this.timePassed.text < Math.floor(this.ns.time)){
           this.timePassed.text = Math.floor(this.ns.time);
       }
       if(this.txtName.text == "Finished"){
           this.txtTime.text =  Math.round(this.totalDuration.text/60) +
":" +  Math.round(this.totalDuration.text%60) + " / " + Math.round(
this.totalDuration.text/60) + ":" +  Math.round(this.totalDuration.text%60);
           }
       else{
           this.txtTime.text = Math.round(this.ns.time/60)+ ":"
+Math.round(this.ns.time%60) + " / " + Math.round(this.totalDuration.text/60)
+ ":" +  Math.round(this.totalDuration.text%60);
           statusBar();
           }


       //bufferLength.text = this.ns.bufferLength;
       if(this.ns.time>= this.totalDuration.text){
           this.txtName.text = "Finished";
           //ns.seek(0);
           }


   }
}

function stopWatchStream()
{

   ns.setBufferTime(lowBufferTime);
   this.txtName.text = "Buffering...";

}

// call back from the server
function returnObjectStatus(obj):Void
{
   tt("returnObjectStatus", obj);

}

// pauses/toggles pausing
function pauseVideo():Void
{
   //ns.pause();
   //this.txtName.text = "Paused";

   if(fileName==""){
   this.txtName.text = "No Video Selected";
   }else{
   //this.videoContainer.clear();
   ns.pause();
       if(pauseStatus==0){
       pauseStatus = 1;
       this.txtName.text = "Paused";
       }else if(videoStatus == 1){
           pauseStatus = 0;
           this.txtName.text = "Buffering...";
           }
   }

   disconnect();
}

function playVideo():Void
{
   var fName = fileName;
   if(fileName==""){
   this.txtName.text = "No Video Selected";
   }else{
   playMovie(fName);
   pauseStatus = 0;
   }
   videoStatus = 1;
}

function muteVideo():Void
{

}
// stops video, clears video object
function stopVideo():Void
{

   if(fileName==""){
   this.txtName.text = "No Video Selected";
   }else{
   this.videoContainer.clear();
   ns.close();
   videoStatus = 0;
   pauseStatus = 0;
   this.txtName.text = "Stopped";
   }
   this.txtTime.text = "";
}

var res = new Object();
res.onResult = function(obj:Object)
{
   tt(obj);
   mydgrid.removeAll();
   var k:Number;
   k=0;
   for(var items:String in obj)
   {
       if(typeof(obj[items]) == "object")
       {
           mydgrid.addItem(obj[items]);
           mydgrid.removeColumnAt(2);
           mydgrid.removeColumnAt(mydgrid.getColumnIndex("size"));
           mydgrid.editField(k, "name", mydgrid.getItemAt(k).name.substr(0,
mydgrid.getItemAt(k).name.length-4));
       }
   k++;
   }
}

function catchVideos()
{
   this.nc.call("demoService.getListOfAvailableFLVs", res);
}


// Create listener object.
function cellPress(evt_obj:Object)
{
   var item = mydgrid.selectedItem;
   tt(mydgrid.selectedItem.name);
   var fName = mydgrid.selectedItem.name;
   playMovie(fName);
};

// Add listener
mydgrid.addEventListener("cellPress", this);
//mydgrid.showHeaders = true;
mydgrid.rollOverColor = "0xAFAEE3";
mydgrid.selectionColor= "0x6869CA";// textRollOverColor
mydgrid.textSelectedColor = "0xFFFFFF";
mydgrid.vScrollPolicy = "auto";
mydgrid.spaceColumnsEqually();
mydgrid.showHeaders = false;


function playMovie(what) {

   this.videoContainer._width = vidWidth;
   this.videoContainer._height = vidHeight;
   stopVideo();
   initNetStream();
   this.txtName.text = "Buffering...";
   this.videoContainer.attachVideo(this.ns);
   //this.videoContainer.seekBar = this.mySeekBar;
   //ns.play("ad/ad.flv", 0, -1, false);
   var actualName = what + ".flv";
   tt(actualName);

   this.ns.play(actualName, 0, -1, false);
   //this.ns.seek(50);
   //tt(this.totalDuration.text);
   //this.ns.time = 50*60;
   //this.ns.seek(1);
}

function reloadMovie(what) {

   this.videoContainer._width = vidWidth;
   this.videoContainer._height = vidHeight;
   //stopVideo();
   initNetStream();
   this.txtName.text = "Buffering...";
   this.videoContainer.attachVideo(this.ns);
   //this.videoContainer.seekBar = this.mySeekBar;
   //ns.play("ad/ad.flv", 0, -1, false);
   var actualName = what + ".flv";

   if(this.timePasses.text!="")
   var timeToSeek = this.timePassed.text;
   //timeToSeek = timeToSeek.substr(0, timeToSeek.indexOf(":")+1)*60 +
timeToSeek.substr(timeToSeek.indexOf(":")+1);

   if(this.totalVal.text!="")
   this.totalDuration.text = Math.round(this.totalVal.text);

   this.ns.play(actualName, 0, -1, false);

   this.ns.seek(timeToSeek);
   tt("seek called ",timeToSeek);
   tt(timeToSeek);
   //this.totalDuration.text = this.ns.
   //this.ns.time = this.txtTime.text.substr(0, this.txtTime.text.indexOf
("/")+1);
   //tt(this.totalDuration.text);
}


this.onLoad = function() {
   connect();
}
_______________________________________________
Red5 mailing list
[email protected]
http://osflash.org/mailman/listinfo/red5_osflash.org

Reply via email to