SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.


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

  2. #2
    Community Advisor silver trophy

    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,547
    Mentioned
    40 Post(s)
    Tagged
    1 Thread(s)
    Comment out the loadNext(); line in the xmlData.onLoad function

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    player.zip

    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

  4. #4
    Community Advisor silver trophy

    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,547
    Mentioned
    40 Post(s)
    Tagged
    1 Thread(s)
    What have you tried to alter yourself? What do you mean by unusable?

  5. #5
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i comment out the loadNext(); at the said function.
    but then it the songs won't load. it shows NaN / NaN

    Personally, i tried

    Code:
    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();
    
        pausetime = mySound.position;
        mySound.stop();
        player_mc.play_mc._visible=true;
        player_mc.pause_mc._visible=false;
        stopBars();
    
    
    }
    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.

  6. #6
    Community Advisor silver trophy

    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,547
    Mentioned
    40 Post(s)
    Tagged
    1 Thread(s)
    Ok try this:

    Code:
    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;
    
    var first_play:Boolean = true;
    
    function newSound(link){
        this.mySound = new Sound();
        
        mySound.onSoundComplete = function(){
            loadNext();
        }
        mySound.setVolume(this.mvolume);
        mySound.loadSound(link,true);
        startBars();
    
        pausetime = mySound.position;
       if(first_play)
       {
          mySound.stop();
          first_play = false;
       }
        player_mc.play_mc._visible=true;
        player_mc.pause_mc._visible=false;
        stopBars();
    }

  7. #7
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    test it. but causes the whole thing to freeze, player window stop responding.
    had to terminate the whole application.

    Hmmmmm..

  8. #8
    Community Advisor silver trophy

    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,547
    Mentioned
    40 Post(s)
    Tagged
    1 Thread(s)
    Tried it with your source files and it works perfectly here?

  9. #9
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it worked! it worked!

    i left out the
    var first_play:Boolean = true;

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

  10. #10
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cell4review View Post
    i hate any autoplayer in any blog
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •