Hi everyone,
I am new to this site and I have to say its amazing, just what I was looking for.
I have figured how this MP3player works: http://www.kirupa.com/web/xml/examples/MP3playlist.htm
** BUT** my problem is, I cant get it to start playing as soon as the movie loads.
**
Instead of clicking the trak I want it to play then clicking the ‘play’ button before it starts playing, I want it to start playing the first track as soon as the movie loads.**
Can anyone help me please. I know its simple but I just cant figure it out, I am new to this.
Below is the Actioscript and XML:
Actionscript:
formatTime = function (millisecs){
var secs = Math.floor(millisecs/1000);
var mins = Math.floor(secs/60);
secs %= 60;
if (secs < 10) secs = "0"+ secs;
if (mins < 10) mins = "0"+ mins;
return mins +":"+ secs;
}
var snd = this.createEmptyMovieClip("SoundController", 1);
snd.init = function(){
snd._sound = new Sound(this);
this.isPlaying = false;
this.position = 0;
loadingbar_mc._xscale = 0;
progressbar_mc._xscale = 0;
}
snd.loadSound = function(url){
this._sound.loadSound(url, true);
stop_btn.onRelease();
this.updateTime();
}
snd.updateTime = function(){
var time = formatTime(snd.position);
if (time_txt.text != time) time_txt.text = time;
}
snd._sound.onSoundComplete = function(){
stop_btn.onRelease();
}
snd.onEnterFrame = function(){
if (this.isPlaying) this.position = this._sound.position;
this.loaded = this._sound.getBytesLoaded()/this._sound.getBytesTotal();
loadingbar_mc._xscale = scrubber_mc._xscale * this.loaded;
progressbar_mc._xscale = loadingbar_mc._xscale * this.position/this._sound.duration;
this.updateTime();
}
play_btn.onRelease = function(){
if (!isPlaying){
snd._sound.start(snd.position/1000);
snd.isPlaying = true;
}
}
pause_btn.onRelease = function(){
if (!snd.isPlaying) return (0);
snd.position = snd._sound.position;
snd._sound.stop();
snd.isPlaying = false;
}
stop_btn.onRelease = function(){
snd.position = 0;
snd._sound.stop();
snd.isPlaying = false;
}
prev_btn.onRelease = function(){
if (snd.node){
if (snd.node.previousSibling) SetSong(snd.node.previousSibling);
else SetSong(snd.node.parentNode.lastChild)
}
}
next_btn.onRelease = function(){
if (snd.node){
if (snd.node.nextSibling) SetSong(snd.node.nextSibling);
else SetSong(snd.node.parentNode.firstChild);
}
}
scrubber_mc.onPress = function(){
if (!snd.loaded) return (0);
var pos = this._xmouse/100;
snd.position = Math.min(snd._sound.duration, pos * snd._sound.duration/snd.loaded);
if (snd.isPlaying) snd._sound.start(snd.position/1000);
}
SetSong = function(node){
snd.node = node;
snd.loadSound(node.attributes.src);
title_txt.text = node.attributes.title;
}
snd.init();
XML:
XMLNode.prototype.moveBefore = function(beforeNode){
if (this == beforeNode) return (0);
beforeNode.parentNode.insertBefore( this.cloneNode(true), beforeNode);
this.removeNode();
}
Clamp = function(min, n, max){
if (n<min) return min;
if (n>max) return max;
return n;
}
var song_spacing = 20;
var over_node;
GenerateSongListing = function(playlist_xml, target_mc){
target_mc = target_mc.createEmptyMovieClip("list_mc",1);
var songs = playlist_xml.firstChild.childNodes;
for (var i=0; i<songs.length; i++){
var song_mc = target_mc.attachMovie("song", "song"+i, i);
song_mc._y = i*song_spacing;
song_mc.node = songs*;
song_mc.title_txt.text = songs*.attributes.title;
song_mc.moved = false;
song_mc.select_btn.onPress = function(){
this._parent.onMouseMove = function(){
if (!this.moved){
dragline_mc._visible = true;
dragline_mc._y = playlist_mc._y + this._y;
highlight_mc._visible = true;
highlight_mc._y = playlist_mc._y + this._y;
this.moved = true;
}
}
}
song_mc.select_btn.onDragOver = function(){
over_node = this._parent.node;
dragline_mc._y = playlist_mc._y + this._parent._y;
}
song_mc.onMouseUp = function(){
if (this.onMouseMove){
delete this.onMouseMove;
dragline_mc._visible = false;
highlight_mc._visible = false;
if (this.moved){
this.node.moveBefore(over_node);
GenerateSongListing(playlist_xml, playlist_mc);
}
}
}
song_mc.select_btn.onRelease = function(){
if (!this._parent.moved){
SetSong(this._parent.node);
}
}
}
}
var playlist_xml = new XML();
playlist_xml.ignoreWhite = true;
playlist_xml.onLoad = function(success){
if (success){
GenerateSongListing(this, playlist_mc);
}else trace("Error loading XML file"); // no success? trace error (wont be seen on web)
}
playlist_xml.load("mp3_playlist.xml");
dragline_mc._visible = false;
highlight_mc._visible = false;
show_mc._visible = false;
show_btn.onRelease = function(){
show_mc._visible = true;
var songs = playlist_xml.firstChild.childNodes;
show_mc.display_txt.text = playlist_xml;
show_mc.display_txt.text = show_mc.display_txt.text.split(">").join(">
");
}
*I want the player to load and start playing the first track as soon as it loads.
Thanks and God Bless
Obed Brefo