Prevent autoplay in my music player - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Prevent autoplay in my music player

I need a simple change for my script below. The music keeps on autoplay as soon as it loads. How do it stop it from autoplay?

I tried stop(); but it doesn't work.
Pls help. Im a noob in this.



[code]
import flash.filters.DropShadowFilter;


var infostruc:Array = [];
var xmlData:XML = new XML();
xmlData.ignoreWhite = true;



//////////////////////////////// VARIABLES START /////////////////////////////
xmlData.load('songs.xml'); //name of XML with songs
this.mvolume = 100; //sound volume
this.equalizer_visible = true; //show equalizer bars
this.shuffle_songs = false; //enable/disable shuffle
var showTime = true; //show actual position text
//////////////////////////////// VARIABLES END /////////////////////////////

mySound = new Sound();
this.player_mc.play_mc._visible=false;
this.current=-1;
this.pausetime = 0;
this.player_mc.song_name_txt.autoSize = true;
this.player_mc.song_artist_txt.autoSize = true;
this.player_mc.mute_mc.stop();


player_mc.bar1_mc._visible = player_mc.bar2_mc._visible = player_mc.bar3_mc._visible = equalizer_visible;
this.player_mc.song_time_txt._visible = showTime;

function newSound(link){
this.mySound = new Sound();

mySound.onSoundComplete = function(){
loadNext();
}
mySound.setVolume(this.mvolume);
mySound.loadSound(link,true);
startBars();


}




function startBars(){
player_mc.bar1_mc.gotoAndPlay(1);
player_mc.bar2_mc.gotoAndPlay(10);
player_mc.bar3_mc.gotoAndPlay(15);

}

function stopBars(){
player_mc.bar1_mc.gotoAndStop(1);
player_mc.bar2_mc.gotoAndStop(1);
player_mc.bar3_mc.gotoAndStop(1);
}


this.player_mc.stop_mc.onPress = function(){
mySound.stop();
pausetime = 0;
player_mc.play_mc._visible=true;
player_mc.pause_mc._visible=false;
stopBars();
}

this.player_mc.play_mc.onPress = function(){
mySound.start(pausetime / 1000);
player_mc.pause_mc._visible=true;
player_mc.play_mc._visible=false;
startBars();
}
this.player_mc.pause_mc.onPress = function(){
pausetime = mySound.position;
mySound.stop();
player_mc.play_mc._visible=true;
player_mc.pause_mc._visible=false;
stopBars();
}

this.player_mc.next_mc.onPress = function(){
loadNext();
player_mc.pause_mc._visible=true;
player_mc.play_mc._visible=false;
}

this.player_mc.prev_mc.onPress = function(){
loadPrev();
player_mc.pause_mc._visible=true;
player_mc.play_mc._visible=false;
}

this.player_mc.mute_mc.onPress = function(){
if(mySound.getVolume() != 0)
{
mySound.setVolume(0);
player_mc.mute_mc.gotoAndStop(2);
}else{
mySound.setVolume(mvolume);
player_mc.mute_mc.gotoAndStop(1);
}
}

function updateName(id){
if(infostruc[id].pic_url)
loadUrl(infostruc[id].pic_url);
else
this.player_mc.picture_mc._visible = false;

if(infostruc[id].name)
this.player_mc.song_name_txt.text = infostruc[id].name;
else
this.player_mc.song_name_txt.text = infostruc[id].link;

if(infostruc[id].artist)
this.player_mc.song_artist_txt.text = infostruc[id].artist;
}

function getNextId(){
if(infostruc.length==current+1)
return 0;
else
return current+1;
}
function getPrevId(){
if(0==current)
return infostruc.length-1;
else
return current-1;
}

function loadNext(){
current = getNextId();
updateName(current);
newSound(infostruc[current].link);
}

function loadPrev(){
this.current = getPrevId();
updateName(this.current);
newSound(infostruc[current].link);
}

function f1()
{
// percent loaded
buffered=Math.floor((mySound.getBytesLoaded()/mySound.getBytesTotal())* 45);

// display progress on the display
//if(buffered<100) { totaltime=buffered; totaltime = totaltime+"%"; }

// resize sound playing bar
player_mc.position._xscale=(mySound.position/mySound.duration)* 45;
player_mc.duration._xscale=buffered;

// display how many seconds played
playedseconds=Math.floor(mySound.position/1000);
playedtime=Math.floor(playedseconds/60) + ":" + playedseconds%60;

timeseconds=Math.floor(mySound.duration/1000);
time=Math.floor(timeseconds/60) + ":" + timeseconds%60;

// if stopped remove sound bar
//if(action=="stop"){ sndbar._xscale=0; }

/*if(pause==1){
pausepos=mySnd.position;
mySnd.stop();
}*/

player_mc.song_time_txt.text = playedtime + ' / ' +time;
//song_time_txt.text = playedtime ;

}



setInterval(f1,100);


var mclistener:Object = new Object();
mclistener.onLoadInit = function(target_mc:MovieClip){
target_mc._width = 75;
target_mc._height = 75;
var myDropShadowFilter = new DropShadowFilter(0,65,0x333333,0.15,15,15,2,3,false,false,false);
target_mc.filters = [myDropShadowFilter];
}

mclistener.onLoadComplete = function(target_mc:MovieClip){
target_mc._parent._parent.gotoAndPlay(2);
}

var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclistener);


MovieClip.prototype.loadUrl = function(url) {
stopBars();
image_mcl.loadClip(url,this.player_mc.picture_mc.image_mc);
}

player_mc.duration.onPress = function(){

var pos = (player_mc._xmouse - player_mc.duration._x) / player_mc.duration._width;
mySound.start( Math.floor(mySound.duration * pos) / 1000 );
}

Array.prototype.shuffle=function(){
for(i=0;i<this.length;i++){
var tmp=this[i];
var randomNum=random(this.length);
this[i]=this[randomNum];
this[randomNum]=tmp;
}
}

xmlData.onLoad = function(success:Boolean):Void {

if (success) {
for (var i:Number = -1; this.childNodes[0].childNodes[++i]; ) {
var cNode:XMLNode = this.childNodes[0].childNodes[i].childNodes;
var url:String = cNode[0].childNodes[0].nodeValue ? unescape(cNode[0].childNodes[0].nodeValue) : unknownSong;
var pic:String = cNode[1].childNodes[0].nodeValue ? unescape(cNode[1].childNodes[0].nodeValue) : unknownSong;
var nm:String = cNode[2].childNodes[0].nodeValue ? unescape(cNode[2].childNodes[0].nodeValue) : unknownSong;
var ar:String = cNode[3].childNodes[0].nodeValue ? unescape(cNode[3].childNodes[0].nodeValue) : unknownSong;
infostruc.push({link:url, name:nm, pic_url:pic,artist:ar});
}
this.song_name_txt.text = "";
if(shuffle_songs==true)
infostruc.shuffle();

loadNext();
} else {
this.song_name_txt.text = "XML error";
this.song_artist_txt.text = "";
}
};


[/code]
Sign In or Register to comment.