skip to main |
skip to sidebar
We love Compewters.
Welcome To COMPEWT Bringing you video tutorials and free resources for your "compewting" endeavours. Check Out the latest Flash Tutorial.
7 November 2009
6 November 2009
How to create a Flash MP3 player
These are video tutorials on how to create an Mp3 in flash with an xml playlist.
If you have come from youtube the code you are looking for is below the videos.
stop(); //stops the frame from starting over and over.
playlist = new XML(); //creates a new xml object
playlist.ignoreWhite = true; //self- explanatory (makes it ignore whitespace)
playlist.onLoad = function(success) { //creates 2 global arrays for the playlist, one of the song title and
if (success) { // cont. one of the file path.
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
trace(songname[i]+" "+songfile[i]);
}
}
_root.createEmptyMovieClip("sound_mc", 1); // generates a new movie clip
_root.sound_mc.sound_obj = new Sound(); // makes our new movie clip hold the song
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]); // this bit loads the song
};
MovieClip.prototype.songStarter = function(file, name) {
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.text_song.text = name;
} else {
this._parent.text_song.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() { // when the sound completes
(song_nr == songfiles.length-1) ? _global.song_nr=0 : _global.song_nr++; // load the next song
_root.sound_mc.songStarter(songfiles[song_nr], songname[song_nr]); // play the next song
};
};
button_play.onRelease = function() {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]); // function of the play button
};
button_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop(); // function for the stop button ... you can work the others out
};
button_next.onRelease = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
button_prev.onRelease = function() {
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
playlist.load("playlist.xml"); // reference to the playlist
The download link for my version :)
http://www.2shared.com/file/8962356/8c13f28a/player_-_Copy.html
Thanks you for viewing this tutorial :)
If you have come from youtube the code you are looking for is below the videos.
stop(); //stops the frame from starting over and over.
playlist = new XML(); //creates a new xml object
playlist.ignoreWhite = true; //self- explanatory (makes it ignore whitespace)
playlist.onLoad = function(success) { //creates 2 global arrays for the playlist, one of the song title and
if (success) { // cont. one of the file path.
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
trace(songname[i]+" "+songfile[i]);
}
}
_root.createEmptyMovieClip("sound_mc", 1); // generates a new movie clip
_root.sound_mc.sound_obj = new Sound(); // makes our new movie clip hold the song
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]); // this bit loads the song
};
MovieClip.prototype.songStarter = function(file, name) {
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.text_song.text = name;
} else {
this._parent.text_song.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() { // when the sound completes
(song_nr == songfiles.length-1) ? _global.song_nr=0 : _global.song_nr++; // load the next song
_root.sound_mc.songStarter(songfiles[song_nr], songname[song_nr]); // play the next song
};
};
button_play.onRelease = function() {
this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]); // function of the play button
};
button_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop(); // function for the stop button ... you can work the others out
};
button_next.onRelease = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
button_prev.onRelease = function() {
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
playlist.load("playlist.xml"); // reference to the playlist
The download link for my version :)
http://www.2shared.com/file/8962356/8c13f28a/player_-_Copy.html
Thanks you for viewing this tutorial :)
Labels:
Flash MP3 Player
4 November 2009
Request a Tutorial
If you want to learn something, that isn't already featured on Compewt you can request it from here using the comment feature and one of our experienced Authors or members may get back to you on it.
To Members offering tutorials with your permission we will feature your tutorial on the blog and give credit to you if we think your tutorial is worthy.
To Members offering tutorials with your permission we will feature your tutorial on the blog and give credit to you if we think your tutorial is worthy.
Welcome To Compewt
Hope you enjoy our wide range of computing tutorials, please keep your comments clean, no swearing with respect for other followers. Thank you :)
Subscribe to:
Posts (Atom)
Labels
- Add videos to your iPod (1)
- Demo (1)
- Flash Contact Form (1)
- Flash MP3 Player (1)
- Flash Tutorial 1: Tweening (1)
- Full Transformers Sig Tutorial (1)
- Screen Recorder (1)
Blog Archive
- Feb 14 - Feb 21 (1)
- Dec 20 - Dec 27 (1)
- Nov 29 - Dec 6 (2)
- Nov 8 - Nov 15 (1)
- Nov 1 - Nov 8 (5)
Copyright © 2009 Compewt | Design: Luka Cvrk | BloggerTemplate Converted by BloggerThemes.Net