I’ll probably feel embarrassed for overseeing something, but at the moment I’m getting a little frustrated with this, so here goes:
I’m building a simple audioplayer.
In frame 1 I have:
mySound = new Sound();
songs = new Array("1.mp3", "2.mp3");
songIndex = 0;
mySound.loadSound(this.songs[songIndex], true);
mySound.start();
var playing = true;
this.onEnterFrame = function() {
if (playing == true){
totalDuration = mySound.duration/1000;
totalSeconds = Math.floor(totalDuration%60);
totalMinutes = Math.floor((totalDuration - totalSeconds)/60);
if(totalSeconds < 10) totalSeconds = "0" + totalSeconds;
this.display.track = songs[songIndex] + " - " + totalMinutes + ":" + totalSeconds;
currentPosition = mySound.position/1000;
currentSeconds = Math.floor(currentPosition%60);
currentMinutes = Math.floor((currentPosition - currentSeconds)/60);
if(currentSeconds < 10) currentSeconds = "0" + currentSeconds;
this.display.timer = currentMinutes + ":" + currentSeconds;
}
else {
currentSeconds = 0;
currentMinutes = 0;
this.display.timer = "0:00";
}
}
MovieClip.prototype.changeTrack = function(x){
this.songIndex = (this.songIndex+x)%this.songs.length;
if (this.songIndex<0) {
this.songIndex += this.songs.length;
}
mySound.stop();
mySound.loadSound(this.songs[songIndex], true);
mySound.start();
}
On my stop-button I have:
on(release){
if (_root.playing == true){
_root.mySound.stop();
_root.playing = false;
}
}
Ok, so the sound stops, no problem thusfar.
On my play-button I have:
on(release){
if(_root.playing != true) {
_root.mySound.loadSound(_root.songs[songIndex], true);
_root.mySound.start();
_root.playing = true;
}
}
So, the sound begins to play from the beginning. However the problem is with the timer: when ‘stop’ is pressed it says 0:00
But, when I press play again it immediately jumps to the time it showed when stop was pushed, e.g. 0:12
Please shed a light on this for me, 'cause I’m very confused. :h:
Thanks.