Toon posts:

flashguru voor hulp gezocht

Pagina: 1
Acties:
  • 47 views sinds 30-01-2008

Verwijderd

Topicstarter
Ben bezig met een mp3 player, op basis van een bestaand script, voor mijn site te maken. nu wil ik dat de player na het laden van de playlist uit een xml bestand, het eerste nummer automatisch gaat spelen.

de code:


// Init //
function init() {
loadSongList("playlist.xml");
_global.loop = false;
_global.paused = false;
_global.playlist = false;
setTrackStatus("stop");
playlist.gotoAndStop(2);
updateSettings();
//Set Component Style
style = new FStyleFormat();
style.arrow = 0x000000;
style.check = 0xffffff;
style.background = 0x000000;
style.backgroundDisabled = 0x000000;
style.shadow = 0x000000;
style.darkshadow = 0x333333;
style.foregroundDisabled = 0x000000;
style.face = 0x999999;
style.highlight = 0xCCCCCC;
style.highlight3D = 0x000000;
style.scrollTrack = 0xCCCCCC;
style.selection = 0x333333;
style.selectionDisabled = 0x000000;
style.selectionUnfocused = 0x000000;
style.textFont = "standard 07_66";
style.textSize = 8;
style.textColor = 0x00CC00;
style.textDisabled = 0x000000;
style.textSelected = 0xFFFFFF
// Apply changes
style.addListener(playlistHolder.myListBox);

}
init();
//////////////////////////////////////////////////////////////

//
////////////// Display Functions

///////////////////////////////
// Load Play List
function loadSongList(URL){
//create new XML
this.mySongList = new XML();
this.mySongList.ignoreWhite = true;
this.mySongList.load(URL);
//callback function creates a playlist
this.mySongList.myClip = this;//onLoad is referenced

to the XML so first create a reference to self
this.mySongList.onLoad = function(){
// this now refers to the XML and myClip is used to

pass the movieclip reference
this.myClip.makePlayList(this);
};
}
function makePlayList(myPlayListXML){
//Hardwired XML reader to read the XML playlist.
//First get the number of songs
this.songNumber =

myPlayListXML.firstChild.firstChild.childNodes.length;
//create playlist object
this.PlayList = new Array(); //new object created
this.songList = new XML();
this.songList = myPlayListXML.firstChild.firstChild;
this.mySong = this.songList.firstChild;

for (var i=0; i<this.songNumber; i++){
song =

this.mySong.firstChild.firstChild.nodeValue;
src =

this.mySong.firstChild.nextSibling.firstChild.nodeValue;
artist =

this.mySong.firstChild.nextSibling.nextSibling.firstChild.node

Value;
this.PlayList[i] = {label:artist + " - " +

song, artist:artist, song:song, source:src};
this.mySong = this.mySong.nextSibling;
}
this.displayPlayList()
}
function displayPlayList(){
playlistHolder.myListBox.setDataProvider(PlayList);
playlistHolder.myListBox.setSelectedIndex(0);
playlistHolder.myListBox.setAutoHideScrollBar(true);


playlistHolder.myListBox.setChangeHandler("playTrack",_root);
}
function updateSettings() {
fldStream.text = "streaming";
fldLoop.text = "looping";
if(_global.stream){
fldStream.textColor = "0x00CC00";
}else{
fldStream.textColor = "0x336600";
positionSlider.btnPosSlider._visible = true;
}
if(_global.loop){
fldLoop.textColor = "0x00CC00";
}else{
fldLoop.textColor = "0x336600";
}
}
function displaySong() {
display.text =

playlistHolder.myListBox.getSelectedItem().artist + "\n";
display.text = display.text +

playlistHolder.myListBox.getSelectedItem().song;
}
function showPlaylist(flag) {
playlistHolder._visible = flag;
}
function sliderControl(){
if(_global.stream){
positionSlider.btnPosSlider._visible = false;
}else{
positionSlider.btnPosSlider._visible = true;
}
if(!_global.seekDrag){
positionSlider.btnPosSlider._x = (252 /

_global.duration) * _global.position;
}
if (_global.volumeDrag) {
display.text = "Volume: " + _global.volume +

"%";
}else if(_global.seekDrag){
display.text = "Seek to: " +

newTrackTime.minutes + ":" +newTrackTime.seconds + "/" +

totalTrackTime.minutes + ":" + totalTrackTime.seconds;
display.text = display.text + " <" +

newTrackTime.percent + "%>";
} else if(_global.error){
display.text = "Loading failed!";
}else{
displaySong();
}
}
function setTrackStatus(flag){
trackStatus.gotoAndStop(flag);
}
//////////////////////////////////////////////////////////////

////
//////////// General SoundObject Functions

///////////////////////
function playTrack (startPos, streaming) {
mySound = new Sound ();
mySound.stop ();
mySound._soundbuftime = 5; // seconds
mySound.onLoad = function(success){
if(success){
_global.error = false;
mySound.start (startPos, 1);
trackTimeDisplay.text =

remainingTrackTime.minutes + ":" + remainingTrackTime.seconds;
displaySong();
}else{
_global.error = true;
}
}
choosenTrack =

playlistHolder.myListBox.getSelectedItem().source;
if(streaming){
mySound.loadSound (choosenTrack, streaming);
}else if(_global.paused){
_global.paused = false;
mySound.loadSound (choosenTrack, streaming);
mySound.start (_global.pausedPosition, 1);
setTrackStatus("play");
}else{
mySound.loadSound (choosenTrack, streaming);
mySound.start (startPos, 1);
setTrackStatus("play");
}
}
function stopTrack () {
mySound.stop ();
setTrackStatus("stop");
}
function pauseTrack(){
_global.paused = true;
_global.pausedPosition = (mySound.position/1000);
mySound.stop();
setTrackStatus("pause");
}
function nextTrack () {
if(playlistHolder.myListBox.getSelectedIndex() ==

playlistHolder.myListBox.getLength()-1){
playlistHolder.myListBox.setSelectedIndex(0);
playTrack (0, _global.stream);
}else{


playlistHolder.myListBox.setSelectedIndex(playlistHolder.myLis

tBox.getSelectedIndex () + 1);
playTrack (0, _global.stream);
}
}
function prevTrack () {
if(playlistHolder.myListBox.getSelectedIndex() == 0){
playlistHolder.myListBox.setSelectedIndex

(playlistHolder.myListBox.getLength()-1);
playTrack (0, _global.stream);
}else{
playlistHolder.myListBox.setSelectedIndex

(playlistHolder.myListBox.getSelectedIndex () - 1);
playTrack (0, _global.stream);
}
}
function setSeek(){
mySound.stop();
mySound.start (_global.newPosition, _global.stream);
setTrackStatus("play");
}
//////////////////////////////////////////////////////////////

//////
// ClipEventHandler
_root.onEnterFrame = function(){
// Sound settings Global Vars
_global.volume = volumeSlider.btnSlider._x;
_global.duration = int(mySound.duration /1000);

//seconds
_global.position = int(mySound.position /1000);

//seconds
_global.newPosition = (_global.duration / 252) *

positionSlider.btnPosSlider._x;
// Volume Control
mySound.setVolume(_global.volume);
// Control Sliders
sliderControl();
// Track Time
totalTrackTime = {};
totalTrackTime.minutes = int(_global.duration/60);
totalTrackTime.seconds = int(_global.duration%60);

newTrackTime = {};
newTrackTime.minutes = int(((_global.duration / 252) *

positionSlider.btnPosSlider._x)/60);
newTrackTime.seconds = int(((_global.duration / 252) *

positionSlider.btnPosSlider._x)%60);
newTrackTime.percent = int((_global.duration / 252) *

positionSlider.btnPosSlider._x / (_global.duration)*100);
if(newTrackTime.seconds < 10){
newTrackTime.seconds = "0" +

newTrackTime.seconds;
}

remainingTrackTime = {};
remainingTrackTime.minutes = int((_global.duration -

_global.position )/ 60);
remainingTrackTime.seconds =int(( _global.duration -

_global.position )%60);
if(remainingTrackTime.seconds < 10){
remainingTrackTime.seconds = "0" +

remainingTrackTime.seconds;
}
trackTimeDisplay.text = remainingTrackTime.minutes +

":" + remainingTrackTime.seconds;
//////////////////////////////////////////////////////////////

//////
// Sound EventHandler
mySound.onSoundComplete = function(){
if(_global.loop){
playTrack (0, _global.stream);
}else{


if(playlistHolder.myListBox.getSelectedIndex() ==

playlistHolder.myListBox.getLength()-1){


playlistHolder.myListBox.setSelectedIndex(0);
playTrack (0, _global.stream);
}else{


playlistHolder.myListBox.setSelectedIndex(playlistHolder.myLis

tBox.getSelectedIndex () + 1);
playTrack (0, _global.stream);
}
}
}
//////////////////////////////////////////////////////////////

/////
// LoadBar Handler
total = mySound.getBytesTotal()/1024;
loaded = mySound.getBytesLoaded()/1024;
percent = loaded / total * 100;
positionSlider.loaderBar._xscale = percent;
}
//////////////////////////////////////////////////////////////

//////


de code voor de btns:


// Button Functions
btnPlay.onPress = function () {
playTrack (0, _global.stream);
};
btnStop.onPress = function () {
stopTrack ();
};
btnPause.onPress = function(){
pauseTrack();
};
btnForward.onPress = function () {
nextTrack ();
};
btnBackward.onPress = function () {
prevTrack ();
};

loop.btnLoop.onPress = function() {
if (!_global.loop) {
_global.loop = true;
loop.gotoAndStop(2);
updateSettings();
} else {
_global.loop = false;
loop.gotoAndStop(1);
updateSettings();
}
};
stream.btnStream.onPress = function() {
if (!_global.stream) {
_global.stream = true;
stream.gotoAndStop(2);
updateSettings();
} else {
_global.stream = false;
stream.gotoAndStop(1);
updateSettings();
}
};
playlist.btnPlaylist.onPress = function() {
if (!_global.playlist) {
_global.playlist = true;
playlist.gotoAndStop(2);
showPlaylist(true);
} else {
_global.playlist = false;
playlist.gotoAndStop(1);
showPlaylist(false);
}
};

  • crisp
  • Registratie: Februari 2000
  • Laatst online: 00:21

crisp

Devver

Pixelated

uit de FAQ:
Kan iemand even ...?
Staat ook duidelijk in de algemene FAQ, maar de users in W&G zijn er niet om klusjes voor anderen op te knappen. Dus vragen als 'kan iemand even een logo maken' of 'wil iemand even een popup-scriptje schrijven' e.d. gaan op slot.
en wat een lap code zeg; je had er minstens even [ code ] tags omheen kunnen zetten :z

Intentionally left blank


Dit topic is gesloten.