AS3에 익숙하지 않아 XML 음악 플레이어를 만들려고합니다. 이유를 알 수 없기 때문에 내가 코딩 한 뮤직 플레이어 (GUI는 무대에 배치되었으므로 코딩은 포함되지 않습니다.)는 텍스트를 표시하거나 음악을 재생하지 않습니다. 지금까지 가지고있는 코드는 다음과 같습니다.ActionScript3에서 XML 음악 플레이어는 어떻게 만듭니 까?
var my_songs:XMLList;
var my_total:Number;
var my_sound:Sound;
var my_channel:SoundChannel;
var current_song:Number = 0;
var song_position:Number;
var song_paused:Boolean;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("playlist.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML = new XML(e.target.data);
my_songs = myXML.SONG;
my_total = my_songs.length();
//playSong(0);
myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
myXMLLoader = null;
}
function playSong(mySong:Number):void {
var myTitle = my_songs[mySong][email protected];
var myURL = my_songs[mySong][email protected];
title_txt.text = myTitle;
if (my_channel) {
my_channel.stop();
my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext);
}
my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();
my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
}
//Jumps to the next track in the list.
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void {
current_song++;
if (current_song>=my_total) {
current_song=0;
}
playSong(current_song);
}
//Jumps position back to previous track in the list.
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void {
current_song--;
if (current_song<0) {
current_song = my_total-1;
}
playSong(current_song);
}
//Pauses music, causing current song to jump back to the beginning when play resumes.
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void {
if (my_channel) {
song_position = my_channel.position;
my_channel.stop();
song_paused=true;
}
}
//Plays music.
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void {
if (song_paused) {
my_channel = my_sound.play(song_position);
song_paused=false;
} else if (!my_channel) {
playSong(current_song);
}
}
누구든지 오류 및 수정 사항을 지적 할 수 있으면 대단히 감사하겠습니다.
오류가 발생 했습니까? – Benny