Stop player from autoplay

Desperately need to get this fix.
Below is the action script of a music player which loads from a xml file.
Problem is, it autoplays as soon as it loads which can be pretty annoying for site visitors.

How to prevent it from autoplaying?
Only play when user clicks on play button and continously play throughout the other songs in the xml file.


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 = "";
	}
};



Comment out the loadNext(); line in the xmlData.onLoad function

Hi,

i tried it. but the player became unusable.
hope you can help. check the attachment for the whole file.
you will need to edit the xml and add few mp3 to the folder for it to work

What have you tried to alter yourself? What do you mean by unusable?

i comment out the loadNext(); at the said function.
but then it the songs won’t load. it shows NaN / NaN

Personally, i tried


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();
[COLOR=#ff0000]
    pausetime = mySound.position;
    mySound.stop();
    player_mc.play_mc._visible=true;
    player_mc.pause_mc._visible=false;
    stopBars();[/COLOR]


}


It does pause the player from playing at start, but unfortunately, it only plays 1 song and not continue with the rest
until the user clicks on the play button again.

Im not good at this flash action script programming.

Ok try this:

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;

[COLOR=#800080]var first_play:Boolean = true;[/COLOR]

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

    [COLOR=#ff0000]pausetime = mySound.position;[/COLOR]
[COLOR=#800080]   if(first_play)
   {
      mySound.stop();
      first_play = false;
   }[/COLOR]
   [COLOR=#ff0000] player_mc.play_mc._visible=true;
    player_mc.pause_mc._visible=false;
    stopBars();[/COLOR]
}

test it. but causes the whole thing to freeze, player window stop responding.
had to terminate the whole application.

Hmmmmm…

Tried it with your source files and it works perfectly here?

it worked! it worked!

i left out the
var first_play:Boolean = true;

my apologies. and thank you so much for the help.

me too. that is why i wanted it to be no “auto play”.
its for a band website which they need to showcase their songs demo before anyone buys it from itunes.