Skip navigation
Acidhunter
Currently Being Moderated

Adjust volume on autoplay with a playlist xml ?

May 4, 2013 6:03 AM

Tags: #xml #volume #playlist

Hello all,

I have a problem i struggle with for some weeks now and i cant find the info i need about it.
On my webpage i have a xml playlist who start to play songs automatic after load.
My issue is that i cant change the volume of these in the player.

What i want is to adjust the volume slider to play the songs with 50% volume for example and not 100% volume as they do now.

Hope anyone can help me out with this as i not was able to find any info about to do this.

Here are the code for my mp3 player:

 

stop();
var songs:Array = new Array();
var curtrack:Number = 0;
var playingsong:Sound = new Sound();

loadSongs();
loadplaylistbox();
loadSong(curtrack);
if (_root.autostart == "false") {
  toggleplaypause();
}

function loadSongs() {
for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
  var songdata:Object = new Object();
  for (songNode=0; songNode<_root.playlistXml.childNodes[0].childNodes[0].childNodes[son gIndex].childNodes.length; songNode++) {
   switch(_root.playlistXml.childNodes[0].childNodes[0].childNodes[songI ndex].childNodes[songNode].nodeName){
   case "creator":
    songdata.artist = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
    break;
   case "title":
    songdata.title = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
    break;
   case "location":
    songdata.location = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
    break;
   }
  }
  songs[songIndex] = songdata;
}
}
function loadSong(track) {
playingsong = new Sound();
playingsong.loadSound(songs[track].location, true);
playingsong.start(0);
updatevolume();
playingsong.onSoundComplete = function() {
  loadSong((curtrack+1)%(songs.length));
};
playpause.gotoAndStop(1);
playpause.playpausebutton.onPress = function() {
  toggleplaypause();
};
songdisplay.text = songs[track].artist+" - "+songs[track].title;
eval("playlistbox.playlistitemcontainer.playlistitem"+curtrack+".play listitemhighlight")._alpha = 100;
eval("playlistbox.playlistitemcontainer.playlistitem"+track+".playlis titemhighlight")._alpha = 1;
curtrack = track;
}
function loadplaylistbox() {
for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
  playlistbox.playlistitemcontainer.attachMovie("playlistitem", "playlistitem"+songIndex, playlistbox.playlistitemcontainer.getNextHighestDepth(), {_x:0, _y:15*songIndex});
  eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex+".pla ylistitemtext").text = songs[songIndex].artist+" - "+songs[songIndex].title;
  eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex).song index = songIndex;
}
}
playpause.playpausebutton.onPress = function() {
toggleplaypause();
};
function toggleplaypause() {
if (playpause._currentframe == 1) {
  playpause.gotoAndStop(2);
  playpause.curpos = playingsong.position;
  playingsong.stop();
} else {
  playpause.gotoAndStop(1);
  playingsong.start(playpause.curpos/1000, 0);
}
playpause.playpausebutton.onPress = function() {
  toggleplaypause();
};
}
onEnterFrame = function () {
if (songdisplay.movingright) {
  //songdisplay.hscroll -= 10;
  if (songdisplay.hscroll<=0) {
   //songdisplay.movingright = false;
  }
} else {
  //songdisplay.hscroll += 10;
  if (songdisplay.hscroll>=songdisplay.maxhscroll) {
   //songdisplay.movingright = true;
  }
}
if (!draggingslider) {
  progressslider._x = (playingsong.position/playingsong.duration)*182-89;
  //if (progressslider._x == 0) {
   //progressslider._x = 61;
  //}
}
if (draggingplaylistscroller) {
  updateplaylistscroll();
}
if (draggingvolmeslider) {
  updatevolume();
}
tempsongtime = "";
if (Math.floor(playingsong.position/60000) == 0) {
  tempsongtime += "0";
} else {
  tempsongtime += Math.floor(playingsong.position/60000);
}
tempsongtime += ":";
if (Math.floor((playingsong.position/1000)%60)<10) {
  tempsongtime += "0";
}
tempsongtime += Math.floor((playingsong.position/1000)%60);
tempsongtime += "/";
if (Math.floor(playingsong.duration/60000) == 0) {
  tempsongtime += "0";
} else {
  tempsongtime += Math.floor(playingsong.duration/60000);
}
tempsongtime += ":";
if (Math.floor((playingsong.duration/1000)%60)<10) {
  tempsongtime += "0";
}
tempsongtime += Math.floor((playingsong.duration/1000)%60);
songtime.text = tempsongtime;

};
progressslider.onPress = function() {
draggingslider = true;
progressslider.startDrag(true, -89, progressslider._y, 93, progressslider._y);
};
progressslider.onRelease = progressslider.onReleaseOutside=function () {
progressslider.stopDrag();
playingsong.start(((progressslider._x+89)/182)*playingsong.duration/1 000, 0);
playpause.gotoAndStop(1);
playpause.playpausebutton.onPress = function() {
  toggleplaypause();
};
draggingslider = false;
};
progressbar.onPress = function() {
playingsong.start(((this._xmouse+2)/182)*playingsong.duration/1000, 0);
playpause.gotoAndStop(1);
playpause.playpausebutton.onPress = function() {
  toggleplaypause();
};
};
volumebar.onPress = function() {
draggingvolmeslider = true;
volumebar.volumeslider.startDrag(true, 0, volumebar.volumeslider._y, 47, volumebar.volumeslider._y);
};
volumebar.onRelease = volumebar.onReleaseOutside=function () {
draggingvolmeslider = false;
volumebar.volumeslider.stopDrag();
updatevolume();
};
function updatevolume() {
playingsong.setVolume((volumebar.volumeslider._x/47)*100);
}
previoussong.onPress = function() {
loadprevioussong();
};
function loadprevioussong() {
var loadtrack = (curtrack-1)%(songs.length);
if (loadtrack<0) {
  loadtrack = songs.length-1;
}
loadSong(loadtrack);
}
nextsong.onPress = function() {
loadnextsong();
};
function loadnextsong() {
var loadtrack = (curtrack+1)%(songs.length);
loadSong(loadtrack);
}
playlistscroller.onPress = function() {
draggingplaylistscroller = true;
playlistscroller.startDrag(true, 452, -80, 452, -59);
};
playlistscroller.onRelease = playlistscroller.onReleaseOutside=function () {
draggingplaylistscroller = false;
playlistscroller.stopDrag();
};
playlistscrollup.onPress = function() {
playlistscroller._y = Math.max(-80, playlistscroller._y-0.5);
updateplaylistscroll();
};
playlistscrolldown.onPress = function() {
playlistscroller._y = Math.min(-59, playlistscroller._y+0.5);
updateplaylistscroll();
};
var mouseListener:Object = new Object();
mouseListener.onMouseWheel = function(delta:Number) {
playlistscroller._y = Math.min(-59, Math.max(-80, playlistscroller._y-delta));
updateplaylistscroll();
};
Mouse.addListener(mouseListener);
playlistscrollbar.onPress = function() {
playlistscroller._y = Math.min(-59, Math.max(-80, _ymouse));
updateplaylistscroll();
};
function updateplaylistscroll() {
playlistbox.playlistitemcontainer._y = -((playlistscroller._y +80)/21)*(playlistbox.playlistitemcontainer._height-69);
}

 
Replies
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 4, 2013 7:08 AM   in reply to Acidhunter

    use playingsong.setVolume():

     

    playingsong.setVolume(50);  // 50%

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 4, 2013 8:25 AM   in reply to Acidhunter

    for loaded sounds, you should assign a volume after loading is complete.  you'll need to start a loop (eg, onEnterFrame) and check the getBytesLoaded() with getBytesTotal() to find when loading is complete.

     

    also, it looks like you're already adjust the volume using a slider (though that code may not be correct).

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 4, 2013 9:38 AM   in reply to Acidhunter

    when you adjust your volumne slider from one extreme to the other, what trace output do you see (copy/paste) using:

    stop();
    var songs:Array = new Array();
    var curtrack:Number = 0;
    var playingsong:Sound = new Sound();

    loadSongs();
    loadplaylistbox();
    loadSong(curtrack);
    if (_root.autostart == "false") {
      toggleplaypause();
    }

    function loadSongs() {
    for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
      var songdata:Object = new Object();
      for (songNode=0; songNode<_root.playlistXml.childNodes[0].childNodes[0].childNodes[son gIndex].childNodes.length; songNode++) {
       switch(_root.playlistXml.childNodes[0].childNodes[0].childNodes[songI ndex].childNodes[songNode].nodeName){
       case "creator":
        songdata.artist = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       case "title":
        songdata.title = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       case "location":
        songdata.location = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       }
      }
      songs[songIndex] = songdata;
    }
    }
    function loadSong(track) {
    playingsong = new Sound();
    playingsong.loadSound(songs[track].location, true);
    playingsong.start(0);
    updatevolume();
    playingsong.onSoundComplete = function() {
      loadSong((curtrack+1)%(songs.length));
    };
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    songdisplay.text = songs[track].artist+" - "+songs[track].title;
    eval("playlistbox.playlistitemcontainer.playlistitem"+curtrack+".play listitemhighlight")._alpha = 100;
    eval("playlistbox.playlistitemcontainer.playlistitem"+track+".playlis titemhighlight")._alpha = 1;
    curtrack = track;
    }
    function loadplaylistbox() {
    for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
      playlistbox.playlistitemcontainer.attachMovie("playlistitem", "playlistitem"+songIndex, playlistbox.playlistitemcontainer.getNextHighestDepth(), {_x:0, _y:15*songIndex});
      eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex+".pla ylistitemtext").text = songs[songIndex].artist+" - "+songs[songIndex].title;
      eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex).song index = songIndex;
    }
    }
    playpause.playpausebutton.onPress = function() {
    toggleplaypause();
    };
    function toggleplaypause() {
    if (playpause._currentframe == 1) {
      playpause.gotoAndStop(2);
      playpause.curpos = playingsong.position;
      playingsong.stop();
    } else {
      playpause.gotoAndStop(1);
      playingsong.start(playpause.curpos/1000, 0);
    }
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    }
    onEnterFrame = function () {
    if (songdisplay.movingright) {
      //songdisplay.hscroll -= 10;
      if (songdisplay.hscroll<=0) {
       //songdisplay.movingright = false;
      }
    } else {
      //songdisplay.hscroll += 10;
      if (songdisplay.hscroll>=songdisplay.maxhscroll) {
       //songdisplay.movingright = true;
      }
    }
    if (!draggingslider) {
      progressslider._x = (playingsong.position/playingsong.duration)*182-89;
      //if (progressslider._x == 0) {
       //progressslider._x = 61;
      //}
    }
    if (draggingplaylistscroller) {
      updateplaylistscroll();
    }
    if (draggingvolmeslider) {
      updatevolume();
    }
    tempsongtime = "";
    if (Math.floor(playingsong.position/60000) == 0) {
      tempsongtime += "0";
    } else {
      tempsongtime += Math.floor(playingsong.position/60000);
    }
    tempsongtime += ":";
    if (Math.floor((playingsong.position/1000)%60)<10) {
      tempsongtime += "0";
    }
    tempsongtime += Math.floor((playingsong.position/1000)%60);
    tempsongtime += "/";
    if (Math.floor(playingsong.duration/60000) == 0) {
      tempsongtime += "0";
    } else {
      tempsongtime += Math.floor(playingsong.duration/60000);
    }
    tempsongtime += ":";
    if (Math.floor((playingsong.duration/1000)%60)<10) {
      tempsongtime += "0";
    }
    tempsongtime += Math.floor((playingsong.duration/1000)%60);
    songtime.text = tempsongtime;

    };
    progressslider.onPress = function() {
    draggingslider = true;
    progressslider.startDrag(true, -89, progressslider._y, 93, progressslider._y);
    };
    progressslider.onRelease = progressslider.onReleaseOutside=function () {
    progressslider.stopDrag();
    playingsong.start(((progressslider._x+89)/182)*playingsong.duration/1 000, 0);
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    draggingslider = false;
    };
    progressbar.onPress = function() {
    playingsong.start(((this._xmouse+2)/182)*playingsong.duration/1000, 0);
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    };
    volumebar.onPress = function() {
    draggingvolmeslider = true;
    volumebar.volumeslider.startDrag(true, 0, volumebar.volumeslider._y, 47, volumebar.volumeslider._y);
    };
    volumebar.onRelease = volumebar.onReleaseOutside=function () {
    draggingvolmeslider = false;
    volumebar.volumeslider.stopDrag();
    updatevolume();
    };
    function updatevolume() {

    trace((volumebar.volumeslider._x / 47) * 100)

    playingsong.setVolume((volumebar.volumeslider._x/47)*100);
    }
    previoussong.onPress = function() {
    loadprevioussong();
    };
    function loadprevioussong() {
    var loadtrack = (curtrack-1)%(songs.length);
    if (loadtrack<0) {
      loadtrack = songs.length-1;
    }
    loadSong(loadtrack);
    }
    nextsong.onPress = function() {
    loadnextsong();
    };
    function loadnextsong() {
    var loadtrack = (curtrack+1)%(songs.length);
    loadSong(loadtrack);
    }
    playlistscroller.onPress = function() {
    draggingplaylistscroller = true;
    playlistscroller.startDrag(true, 452, -80, 452, -59);
    };
    playlistscroller.onRelease = playlistscroller.onReleaseOutside=function () {
    draggingplaylistscroller = false;
    playlistscroller.stopDrag();
    };
    playlistscrollup.onPress = function() {
    playlistscroller._y = Math.max(-80, playlistscroller._y-0.5);
    updateplaylistscroll();
    };
    playlistscrolldown.onPress = function() {
    playlistscroller._y = Math.min(-59, playlistscroller._y+0.5);
    updateplaylistscroll();
    };
    var mouseListener:Object = new Object();
    mouseListener.onMouseWheel = function(delta:Number) {
    playlistscroller._y = Math.min(-59, Math.max(-80, playlistscroller._y-delta));
    updateplaylistscroll();
    };
    Mouse.addListener(mouseListener);
    playlistscrollbar.onPress = function() {
    playlistscroller._y = Math.min(-59, Math.max(-80, _ymouse));
    updateplaylistscroll();
    };
    function updateplaylistscroll() {
    playlistbox.playlistitemcontainer._y = -((playlistscroller._y +80)/21)*(playlistbox.playlistitemcontainer._height-69);
    }

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 4, 2013 11:32 AM   in reply to Acidhunter

    when you move that slider (after your sound starts to play), does it change the sound's volume?

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 4, 2013 3:34 PM   in reply to Acidhunter

    ok, so what is that you want to change?

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 5, 2013 6:25 AM   in reply to Acidhunter

    use the slider and the code below to get a volume of about 50% and note the volumeslider's _x value:

     

    you can then assign that value at the start of your app and call updatevolume() after your first sound loads.

     

    stop();
    var songs:Array = new Array();
    var curtrack:Number = 0;
    var playingsong:Sound = new Sound();

    loadSongs();
    loadplaylistbox();
    loadSong(curtrack);
    if (_root.autostart == "false") {
      toggleplaypause();
    }

    function loadSongs() {
    for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
      var songdata:Object = new Object();
      for (songNode=0; songNode<_root.playlistXml.childNodes[0].childNodes[0].childNodes[son gIndex].childNodes.length; songNode++) {
       switch(_root.playlistXml.childNodes[0].childNodes[0].childNodes[songI ndex].childNodes[songNode].nodeName){
       case "creator":
        songdata.artist = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       case "title":
        songdata.title = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       case "location":
        songdata.location = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       }
      }
      songs[songIndex] = songdata;
    }
    }
    function loadSong(track) {
    playingsong = new Sound();
    playingsong.loadSound(songs[track].location, true);
    playingsong.start(0);
    updatevolume();
    playingsong.onSoundComplete = function() {
      loadSong((curtrack+1)%(songs.length));
    };
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    songdisplay.text = songs[track].artist+" - "+songs[track].title;
    eval("playlistbox.playlistitemcontainer.playlistitem"+curtrack+".play listitemhighlight")._alpha = 100;
    eval("playlistbox.playlistitemcontainer.playlistitem"+track+".playlis titemhighlight")._alpha = 1;
    curtrack = track;
    }
    function loadplaylistbox() {
    for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
      playlistbox.playlistitemcontainer.attachMovie("playlistitem", "playlistitem"+songIndex, playlistbox.playlistitemcontainer.getNextHighestDepth(), {_x:0, _y:15*songIndex});
      eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex+".pla ylistitemtext").text = songs[songIndex].artist+" - "+songs[songIndex].title;
      eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex).song index = songIndex;
    }
    }
    playpause.playpausebutton.onPress = function() {
    toggleplaypause();
    };
    function toggleplaypause() {
    if (playpause._currentframe == 1) {
      playpause.gotoAndStop(2);
      playpause.curpos = playingsong.position;
      playingsong.stop();
    } else {
      playpause.gotoAndStop(1);
      playingsong.start(playpause.curpos/1000, 0);
    }
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    }
    onEnterFrame = function () {
    if (songdisplay.movingright) {
      //songdisplay.hscroll -= 10;
      if (songdisplay.hscroll<=0) {
       //songdisplay.movingright = false;
      }
    } else {
      //songdisplay.hscroll += 10;
      if (songdisplay.hscroll>=songdisplay.maxhscroll) {
       //songdisplay.movingright = true;
      }
    }
    if (!draggingslider) {
      progressslider._x = (playingsong.position/playingsong.duration)*182-89;
      //if (progressslider._x == 0) {
       //progressslider._x = 61;
      //}
    }
    if (draggingplaylistscroller) {
      updateplaylistscroll();
    }
    if (draggingvolmeslider) {
      updatevolume();
    }
    tempsongtime = "";
    if (Math.floor(playingsong.position/60000) == 0) {
      tempsongtime += "0";
    } else {
      tempsongtime += Math.floor(playingsong.position/60000);
    }
    tempsongtime += ":";
    if (Math.floor((playingsong.position/1000)%60)<10) {
      tempsongtime += "0";
    }
    tempsongtime += Math.floor((playingsong.position/1000)%60);
    tempsongtime += "/";
    if (Math.floor(playingsong.duration/60000) == 0) {
      tempsongtime += "0";
    } else {
      tempsongtime += Math.floor(playingsong.duration/60000);
    }
    tempsongtime += ":";
    if (Math.floor((playingsong.duration/1000)%60)<10) {
      tempsongtime += "0";
    }
    tempsongtime += Math.floor((playingsong.duration/1000)%60);
    songtime.text = tempsongtime;

    };
    progressslider.onPress = function() {
    draggingslider = true;
    progressslider.startDrag(true, -89, progressslider._y, 93, progressslider._y);
    };
    progressslider.onRelease = progressslider.onReleaseOutside=function () {
    progressslider.stopDrag();
    playingsong.start(((progressslider._x+89)/182)*playingsong.duration/1 000, 0);
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    draggingslider = false;
    };
    progressbar.onPress = function() {
    playingsong.start(((this._xmouse+2)/182)*playingsong.duration/1000, 0);
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    };
    volumebar.onPress = function() {
    draggingvolmeslider = true;
    volumebar.volumeslider.startDrag(true, 0, volumebar.volumeslider._y, 47, volumebar.volumeslider._y);
    };
    volumebar.onRelease = volumebar.onReleaseOutside=function () {
    draggingvolmeslider = false;
    volumebar.volumeslider.stopDrag();
    updatevolume();
    };
    function updatevolume() {

    trace((volumebar.volumeslider._x / 47) * 100+" : volumeSlider _x= "+volumebar.volumeslider._x)

    playingsong.setVolume((volumebar.volumeslider._x/47)*100);
    }
    previoussong.onPress = function() {
    loadprevioussong();
    };
    function loadprevioussong() {
    var loadtrack = (curtrack-1)%(songs.length);
    if (loadtrack<0) {
      loadtrack = songs.length-1;
    }
    loadSong(loadtrack);
    }
    nextsong.onPress = function() {
    loadnextsong();
    };
    function loadnextsong() {
    var loadtrack = (curtrack+1)%(songs.length);
    loadSong(loadtrack);
    }
    playlistscroller.onPress = function() {
    draggingplaylistscroller = true;
    playlistscroller.startDrag(true, 452, -80, 452, -59);
    };
    playlistscroller.onRelease = playlistscroller.onReleaseOutside=function () {
    draggingplaylistscroller = false;
    playlistscroller.stopDrag();
    };
    playlistscrollup.onPress = function() {
    playlistscroller._y = Math.max(-80, playlistscroller._y-0.5);
    updateplaylistscroll();
    };
    playlistscrolldown.onPress = function() {
    playlistscroller._y = Math.min(-59, playlistscroller._y+0.5);
    updateplaylistscroll();
    };
    var mouseListener:Object = new Object();
    mouseListener.onMouseWheel = function(delta:Number) {
    playlistscroller._y = Math.min(-59, Math.max(-80, playlistscroller._y-delta));
    updateplaylistscroll();
    };
    Mouse.addListener(mouseListener);
    playlistscrollbar.onPress = function() {
    playlistscroller._y = Math.min(-59, Math.max(-80, _ymouse));
    updateplaylistscroll();
    };
    function updateplaylistscroll() {
    playlistbox.playlistitemcontainer._y = -((playlistscroller._y +80)/21)*(playlistbox.playlistitemcontainer._height-69);
    }

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 5, 2013 8:43 AM   in reply to kglad

    use:

     

     

    stop();
    var songs:Array = new Array();
    var curtrack:Number = 0;
    var playingsong:Sound = new Sound();

    volumebar.volumeslider._x = 29;

    updatevolume();

    loadSongs();
    loadplaylistbox();
    loadSong(curtrack);
    if (_root.autostart == "false") {
      toggleplaypause();
    }

    function loadSongs() {
    for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
      var songdata:Object = new Object();
      for (songNode=0; songNode<_root.playlistXml.childNodes[0].childNodes[0].childNodes[son gIndex].childNodes.length; songNode++) {
       switch(_root.playlistXml.childNodes[0].childNodes[0].childNodes[songI ndex].childNodes[songNode].nodeName){
       case "creator":
        songdata.artist = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       case "title":
        songdata.title = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       case "location":
        songdata.location = _root.playlistXml.childNodes[0].childNodes[0].childNodes[songIndex].c hildNodes[songNode].childNodes[0].nodeValue;
        break;
       }
      }
      songs[songIndex] = songdata;
    }
    }
    function loadSong(track) {
    playingsong = new Sound();
    playingsong.loadSound(songs[track].location, true);
    playingsong.start(0);
    updatevolume();
    playingsong.onSoundComplete = function() {
      loadSong((curtrack+1)%(songs.length));
    };
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    songdisplay.text = songs[track].artist+" - "+songs[track].title;
    eval("playlistbox.playlistitemcontainer.playlistitem"+curtrack+".play listitemhighlight")._alpha = 100;
    eval("playlistbox.playlistitemcontainer.playlistitem"+track+".playlis titemhighlight")._alpha = 1;
    curtrack = track;
    }
    function loadplaylistbox() {
    for (songIndex=0; songIndex<_root.playlistXml.childNodes[0].childNodes[0].childNodes.le ngth; songIndex++) {
      playlistbox.playlistitemcontainer.attachMovie("playlistitem", "playlistitem"+songIndex, playlistbox.playlistitemcontainer.getNextHighestDepth(), {_x:0, _y:15*songIndex});
      eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex+".pla ylistitemtext").text = songs[songIndex].artist+" - "+songs[songIndex].title;
      eval("playlistbox.playlistitemcontainer.playlistitem"+songIndex).song index = songIndex;
    }
    }
    playpause.playpausebutton.onPress = function() {
    toggleplaypause();
    };
    function toggleplaypause() {
    if (playpause._currentframe == 1) {
      playpause.gotoAndStop(2);
      playpause.curpos = playingsong.position;
      playingsong.stop();
    } else {
      playpause.gotoAndStop(1);
      playingsong.start(playpause.curpos/1000, 0);
    }
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    }
    onEnterFrame = function () {
    if (songdisplay.movingright) {
      //songdisplay.hscroll -= 10;
      if (songdisplay.hscroll<=0) {
       //songdisplay.movingright = false;
      }
    } else {
      //songdisplay.hscroll += 10;
      if (songdisplay.hscroll>=songdisplay.maxhscroll) {
       //songdisplay.movingright = true;
      }
    }
    if (!draggingslider) {
      progressslider._x = (playingsong.position/playingsong.duration)*182-89;
      //if (progressslider._x == 0) {
       //progressslider._x = 61;
      //}
    }
    if (draggingplaylistscroller) {
      updateplaylistscroll();
    }
    if (draggingvolmeslider) {
      updatevolume();
    }
    tempsongtime = "";
    if (Math.floor(playingsong.position/60000) == 0) {
      tempsongtime += "0";
    } else {
      tempsongtime += Math.floor(playingsong.position/60000);
    }
    tempsongtime += ":";
    if (Math.floor((playingsong.position/1000)%60)<10) {
      tempsongtime += "0";
    }
    tempsongtime += Math.floor((playingsong.position/1000)%60);
    tempsongtime += "/";
    if (Math.floor(playingsong.duration/60000) == 0) {
      tempsongtime += "0";
    } else {
      tempsongtime += Math.floor(playingsong.duration/60000);
    }
    tempsongtime += ":";
    if (Math.floor((playingsong.duration/1000)%60)<10) {
      tempsongtime += "0";
    }
    tempsongtime += Math.floor((playingsong.duration/1000)%60);
    songtime.text = tempsongtime;

    };
    progressslider.onPress = function() {
    draggingslider = true;
    progressslider.startDrag(true, -89, progressslider._y, 93, progressslider._y);
    };
    progressslider.onRelease = progressslider.onReleaseOutside=function () {
    progressslider.stopDrag();
    playingsong.start(((progressslider._x+89)/182)*playingsong.duration/1 000, 0);
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    draggingslider = false;
    };
    progressbar.onPress = function() {
    playingsong.start(((this._xmouse+2)/182)*playingsong.duration/1000, 0);
    playpause.gotoAndStop(1);
    playpause.playpausebutton.onPress = function() {
      toggleplaypause();
    };
    };
    volumebar.onPress = function() {
    draggingvolmeslider = true;
    volumebar.volumeslider.startDrag(true, 0, volumebar.volumeslider._y, 47, volumebar.volumeslider._y);
    };
    volumebar.onRelease = volumebar.onReleaseOutside=function () {
    draggingvolmeslider = false;
    volumebar.volumeslider.stopDrag();
    updatevolume();
    };
    function updatevolume() {

    // trace((volumebar.volumeslider._x / 47) * 100+" : volumeSlider _x= "+volumebar.volumeslider._x)  <- no longer needed

    playingsong.setVolume((volumebar.volumeslider._x/47)*100);
    }
    previoussong.onPress = function() {
    loadprevioussong();
    };
    function loadprevioussong() {
    var loadtrack = (curtrack-1)%(songs.length);
    if (loadtrack<0) {
      loadtrack = songs.length-1;
    }
    loadSong(loadtrack);
    }
    nextsong.onPress = function() {
    loadnextsong();
    };
    function loadnextsong() {
    var loadtrack = (curtrack+1)%(songs.length);
    loadSong(loadtrack);
    }
    playlistscroller.onPress = function() {
    draggingplaylistscroller = true;
    playlistscroller.startDrag(true, 452, -80, 452, -59);
    };
    playlistscroller.onRelease = playlistscroller.onReleaseOutside=function () {
    draggingplaylistscroller = false;
    playlistscroller.stopDrag();
    };
    playlistscrollup.onPress = function() {
    playlistscroller._y = Math.max(-80, playlistscroller._y-0.5);
    updateplaylistscroll();
    };
    playlistscrolldown.onPress = function() {
    playlistscroller._y = Math.min(-59, playlistscroller._y+0.5);
    updateplaylistscroll();
    };
    var mouseListener:Object = new Object();
    mouseListener.onMouseWheel = function(delta:Number) {
    playlistscroller._y = Math.min(-59, Math.max(-80, playlistscroller._y-delta));
    updateplaylistscroll();
    };
    Mouse.addListener(mouseListener);
    playlistscrollbar.onPress = function() {
    playlistscroller._y = Math.min(-59, Math.max(-80, _ymouse));
    updateplaylistscroll();
    };
    function updateplaylistscroll() {
    playlistbox.playlistitemcontainer._y = -((playlistscroller._y +80)/21)*(playlistbox.playlistitemcontainer._height-69);
    }

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 5, 2013 1:02 PM   in reply to Acidhunter

    uncomment that trace() statement in updatevolume() to see if something is calling that function around the 4-5 sec mark when you hear the volume increase.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    May 9, 2013 10:32 AM   in reply to Acidhunter

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points