PDA

View Full Version : cant stop audio with netstream


jeffmikolai
09-08-2009, 12:05 AM
This is driving me crazy. When I exit the page that is playing video it does not stop the audio.

Here is my code;


import mx.transitions.Tween;
import mx.transitions.easing.Regular;

var path:String = arrayImage[currentIndex-1];

var netCon:NetConnection = new NetConnection();
netCon.connect(null);

var netStream:NetStream = new NetStream(netCon);

netStream.setBufferTime(10);

video.attachVideo(netStream);

var isPlay:Boolean = false;
var soundOn:Boolean=true;
var sound:Sound = new Sound();

var dur:Number = new Number();

var ps:Boolean = true;


var arrayImage:Array = new Array();
var arrayThumb:Array = new Array();
var arrayTitle:Array = new Array();
var arrayTitle2:Array = new Array();
var arrayDescription:Array = new Array();
var currentIndex:Number = 1;

/////////////////////////////////////////////
desc._alpha = 0;


var gallery_xml:XML = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(ok) {
if (ok) {
parsXML();
arrayThumbs();
MCscroll.mcContent.btnVideo1.gotoAndStop(10);
_play._visible = false;
getDes();

MCscroll.renewScroll();

}else{
}
};


// loading xml
gallery_xml.load("cgal_video.xml");


function parsXML(){
var mainGalleryNode = gallery_xml.childNodes[0].childNodes;
var pathC:String = mainGalleryNode[0].attributes.path;
lenGall = mainGalleryNode[0].childNodes.length;
trace(lenGall)

for (var i = 0; i<lenGall; i++) {
arrayImage[i] = pathC+mainGalleryNode[0].childNodes[i].attributes.img;
arrayThumb[i] = pathC+mainGalleryNode[0].childNodes[i].attributes.thumbnail;
arrayTitle[i] = mainGalleryNode[0].childNodes[i].attributes.title;
arrayTitle2[i] = mainGalleryNode[0].childNodes[i].attributes.seriesTitle;
arrayDescription[i] = mainGalleryNode[0].childNodes[i].attributes.description;
}

}
function arrayThumbs() {

for (var i = 1; i<=lenGall; i++) {
trace(lenGall)
MCscroll.mcContent.attachMovie("btnVideo", "btnVideo"+i, i);
var thumbName:MovieClip = MCscroll.mcContent["btnVideo"+i];
thumbName.index = i;

thumbName.btn._txt.text = "0"+i + ". " + arrayTitle[i-1];

if(i>9)
{
thumbName.btn._txt.text = i + ". " + arrayTitle[i-1];
}

thumbName._y = Math.floor((thumbName._height+4)*(i-1));
thumbName._x = 30;


thumbName.onRollOver = function() {
if(this.index!= currentIndex)
{
this.gotoAndPlay("over");
}
};
thumbName.onRollOut = thumbName.onReleaseOutside=function () {
if(this.index!= currentIndex)
{
this.gotoAndPlay("out");
}
};
thumbName.onRelease = function() {
if(this.index!= currentIndex)
{

_play._visible = false;
_pause._visible = true;
MCscroll.mcContent["btnVideo"+currentIndex].gotoAndPlay("out");
currentIndex = this.index;
playMov();
getDes();
}
}
}
}

getDes = function()
{
_txtDescr.multiline = true;
_txtDescr.wordWrap = true;
_txtTitle.text = arrayTitle[currentIndex-1];
_txtTitle2.text = arrayTitle2[currentIndex-1];
_txtDescr.text = arrayDescription[currentIndex-1];

}

_volBtn.onRelease = function() {
if(soundOn == true){
this.soundbut.gotoAndPlay(2);
sound.setVolume((this.btn._currentframe == 1) ? 100 : 0);
soundOn=false;
trace("off")
}
else{
this.soundbut.gotoAndPlay(1);
sound.setVolume((this.btn._currentframe == 1) ? 0 : 100);
soundOn=true;
trace("on")
}
};


playMov = function()
{
path = arrayImage[currentIndex-1];
netStream.play(path);
isPlay = true;
}

_click.onRelease = function() {
if (!isPlay) {
this._visible = false;
//netStream.play(path);
playMov();
}
};

_timeBarBack.onPress = function() {
if (isPlay) {
netStream.pause();
_timeBar.back._width = this._xmouse;
netStream.seek(dur*this._xmouse/this._width);
this.onMouseMove = function() {
if (this._xmouse>0 && this._xmouse<this._width) {
_timeBar.back._width = this._xmouse;
netStream.seek(dur*this._xmouse/this._width);
}
};
}
};

_timeBarBack.onRelease = _timeBarBack.onReleaseOutside=function () {
netStream.pause();
this.onMouseMove = null;
};

_play.onRelease = function() {
trace(ps)
isPlay = true;
if(ps==true)
{
netStream.pause();
this._visible = false;
}
else
{
netStream.play(path);

_pause._visible = true;
}
};

_pause.onRelease = function(){
isPlay = false;
netStream.pause();
_play._visible = true;
ps = true;
}

_prev.onRelease = function() {
MCscroll.mcContent["btnVideo"+currentIndex].gotoAndPlay("out");
currentIndex-=1;
MCscroll.mcContent["btnVideo"+currentIndex].gotoAndPlay("over");
playMov();
getDes();

}
_next.onRelease = function() {
MCscroll.mcContent["btnVideo"+currentIndex].gotoAndPlay("out");
currentIndex+=1;
MCscroll.mcContent["btnVideo"+currentIndex].gotoAndPlay("over");
playMov();
getDes();

}

netStream.onStatus = function(infoObject:Object) {
for (var prop in infoObject) {
if (infoObject[prop] == "NetStream.Play.Start") {
isPlay = true;
_click._visible = false;
_click.useHandCursor = false;
}
if (infoObject[prop] == "NetStream.Play.Stop") {
isPlay = false;
_click._visible = true;
_click.useHandCursor = true;
//????????????
netStream.close();
}
}
};

netStream.onMetaData = function(infoObject:Object) {
for (var prop in infoObject) {
if (prop == "duration") {
// write duration
dur = Math.round(Number(infoObject[prop]));
sec2min(_totalTime, Math.round(Number(infoObject[prop])));
}
}
};

var sec2min = function (target:TextField, num:Number):Void {
target.text = (Math.floor(num/60)<10) ? "0"+String(Math.floor(num/60)) : String(Math.floor(num/60));
target.text += ":";
target.text += (num%60)<10 ? "0"+String((num%60)) : String((num%60));
};

var inter:Number = setInterval(this, "checkTime", 1, netStream);

var checkTime = function(ns:NetStream) {
sec2min(_curTime, Math.round(ns.time));
_timeBar.back._width = Math.round(230*ns.time/dur);
_bufLength.back._width = (_timeBarBack._width*ns.bytesLoaded/ns.bytesTotal);
};

trace(isPlay)





This is my exit routine...

exit.exitBut.onPress = function(){



_root.mainMain.main.snd._sound.stop();
_root.mainMain.main.moveBut.gotoAndPlay("p2");
_root.mainMain.main._content._visible = false;
_root.mainMain.main._menu.gotoAndPlay(1);
}