PDA

Volledige versie bekijken : Jukebox automatisch naar volgende song


slabbetje
%Europe/Berlin %702 %2009, 16:51
Beste flashers,
Ik ben een beginnende flash programmeur en nu moest ik voor school een jukebox maken.
Dit is al aardig gelukt alleen nu wil ik er voor zorgen dat hij automatisch het volgende nummer afspeelt wanneer het huidige nummer is afgelopen.

Het is al een flink script en het zal me niks verbazen als er rotzooi tussen staat
Als je dat irriteerd meld het dan even want zo leer ik teminste gelijk goed as scripten :P

Alvast bedankt voor het kijken/helpen.

import flash.display.Loader;
import flash.net.URLRequest;

var frame:content_main = new content_main;
var kanaal:SoundChannel = new SoundChannel();
var isPlaying:Boolean = false;
var nowPlaying;
var nextPlaying;
var nowPosition:int = 9000;
var ba:ByteArray = new ByteArray();
var loader:URLLoader = new URLLoader();
var imageLoader:Loader;
var xml:XML;
var albumList:Array = new Array();
var musicList:Array = new Array();

loader.addEventListener(Event.COMPLETE, onLoaded);
frame.lb.addEventListener(Event.CHANGE, muziekChange);
frame.btn_stop.addEventListener(MouseEvent.CLICK, stopMuziek);
frame.btn_start.addEventListener(MouseEvent.CLICK, startMuziek);
frame.btn_pauze.addEventListener(MouseEvent.CLICK, pauzeMuziek);
kanaal.addEventListener(Event.SOUND_COMPLETE, nextMuziek);
addEventListener(Event.ENTER_FRAME, spectrum);

addChild(frame);

/*
**Hiermee Positioneer je de buttons
*/
frame.btn_stop.x = 35;
frame.btn_stop.y = 228;

frame.btn_start.x = 10;
frame.btn_start.y = 228;

frame.btn_pauze.visible = false;
frame.btn_pauze.x = 10;
frame.btn_pauze.y = 228;

frame.imgArea.visible = false;

/*
**Hier is de XML ingeladen
*/
function onLoaded(e:Event):void {
xml = new XML(e.target.data);
var il:XMLList = xml.alles.item;
for (var i:uint=0; i<il.length(); i++) {
frame.lb.addItem({data:il.id.text()[i],label:il.title.text()[i]});
albumList.push(il.album_link.text()[i]);
musicList.push(il.link.text()[i]);
}
nowPlaying = il.link.text()[0];
loadImage("albums/" + il.album_link.text()[0]);
}

/*
**Hiermee verander je de muziek + Album image
*/
function muziekChange(e:Event):void {
//trace(lb.selectedItem.data);
SoundMixer.stopAll();
var geluid:Sound = new Sound();
geluid.load(new URLRequest(musicList[frame.lb.selectedItem.data]));
kanaal = geluid.play(90000);
nowPlaying = musicList[frame.lb.selectedItem.data];
nextPlaying = musicList[frame.lb.selectedItem.data =+ 1];
isPlaying = true;
loadImage("albums/" + albumList[frame.lb.selectedItem.data]);
trace(nextPlaying);
}

/*
**Hier komt het geluids spectrum
*/
function spectrum(e:Event):void {
SoundMixer.computeSpectrum(ba);

for (var i:uint=0; i<6; i++) {
var num:Number = Math.floor(-ba.readFloat()*5 + 5);

if (i == 1) {
frame.spec1.scaleY = -num;
frame.spec1.y = 245;
}
if (i == 2) {
frame.spec2.scaleY = -num;
frame.spec2.y = 245;
}
if (i == 3) {
frame.spec3.scaleY = -num;
frame.spec3.y = 245;
}
if (i == 4) {
frame.spec4.scaleY = -num;
frame.spec4.y = 245;
}
if (i == 5) {
frame.spec5.scaleY = -num;
frame.spec5.y = 245;
} else {
}
}
}

/*
**Hier komt de Stop functie
*/
function stopMuziek(e:MouseEvent):void {
if (isPlaying == true) {
kanaal.stop();
isPlaying = false;
nowPosition = 0;
frame.btn_start.visible=true;
frame.btn_pauze.visible=false;
} else {
}
}

/*
**Hier komt de Start functie
*/
function startMuziek(e:MouseEvent):void {
if (isPlaying == false) {
var geluid:Sound = new Sound();
geluid.load(new URLRequest(nowPlaying));
kanaal = geluid.play(nowPosition);
isPlaying = true;
frame.btn_start.visible=false;
frame.btn_pauze.visible=true;
}
}
/*
**Hier komt de Pauze functie
*/
function pauzeMuziek(e:MouseEvent):void {
if (isPlaying == true) {
nowPosition = kanaal.position;
kanaal.stop();
isPlaying = false;
frame.btn_start.visible=true;
frame.btn_pauze.visible=false;
}
}
/*
**Hier komt de Next Song functie
*/
function nextMuziek(e:Event):void {
var geluid:Sound = new Sound();
geluid.load(new URLRequest(nextPlaying));
kanaal = geluid.play();
trace("functie uitgevoerd");
}

/*
**Hier komen de Album functies
*/
function loadImage(url:String):void {

// Set properties on my Loader object
imageLoader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, imageLoading);
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imageLoaded);

}

function imageLoaded(e:Event):void {

// Load Image
frame.imgArea.visible = true;
frame.imgArea.addChild(imageLoader);

}

function imageLoading(e:ProgressEvent):void {
frame.imgArea.visible = false;
}

loader.load(new URLRequest("muziek.xml"));

WickedMind
%Europe/Berlin %725 %2009, 17:24
Ga es aan de slag met soundComplete event:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/SoundChannel.html#event:soundComplete

en dan je nextMuziek function aanroepen als tie dispatched wordt

slabbetje
%Europe/Berlin %735 %2009, 17:38
Ga es aan de slag met soundComplete event:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/SoundChannel.html#event:soundComplete

en dan je nextMuziek function aanroepen als tie dispatched wordt

Dit heb ik gedaan...
Dit heb ik namenlijk al gevonden op google

kanaal.addEventListener(Event.SOUND_COMPLETE, nextMuziek);

WickedMind
%Europe/Berlin %740 %2009, 17:45
trace eens wat er gebeurd in nextMuziek?

slabbetje
%Europe/Berlin %816 %2009, 19:35
ik heb het gefixed

rangelier
%Europe/Berlin %844 %2009, 20:16
hey,

mischien ook handig voor andere mensen om je oplossing ff te posten :)

greetzzz