MP3 Player Problems
ok guys, tried make mp3 player tutorial here http://www.republicofcode.com/tutorials/flash/as3musicplayer/
the player , play, pause, next, previous etc. functions work fine, want make improvements
1/i want have fully-functional loadbar , seekbar player
2/could possible? want player automatically plays movie clip(that shows next song in playlist) @ last 10 second of every song
3/i want merge both play , pause buttons, save space
please guys i'm new as3 , these event listeners thingy (because of old computer, last 2 years flash in as2 - flash 8 )
here's code:
import flash.net.urlloader;
import flash.net.urlrequest;
import flash.events.event;
import flash.media.sound;
import flash.media.soundchannel;
import flash.events.mouseevent;
var my_songs:xmllist;
var my_total:number;
var my_sound:sound;
var my_channel:soundchannel;
var song_position:number;
var song_paused:boolean;
var current_song:number = 0;
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();
myxmlloader.removeeventlistener(event.complete, processxml);
myxmlloader = null;
}
function playsong(mysong:number):void{
var mytitle = my_songs[mysong].@title;
var myartist = my_songs[mysong].@artist;
var myalbum = my_songs[mysong].@album;
var myurl = my_songs[mysong].@url;
title_txt.text = mytitle;
artist_txt.text = myartist;
album_txt.text = myalbum;
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);
}
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);
play_mc.gotoandplay(1);
}
}
next_btn.addeventlistener(mouseevent.click, onnext);
function onnext(e:event):void{
current_song++;
if (current_song>=my_total){
current_song = 0;
}
playsong(current_song);
play_mc.gotoandplay(1);
}
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);
play_mc.gotoandplay(1);
}
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;
}
}
play_mc.gotoandstop(1);
1. sound class has progress event , bytesloaded/bytestotal properties can use loadbar. has length property , soundchannel's position property, can create playbar.
2. autoplay, call onnext when soundchannel soundcomplete event dispatched. (you can pass null or assign default event in onnext.)
3. what's problem?
More discussions in ActionScript 3
adobe
Comments
Post a Comment