Pause and Mute for music?

I have followed the Music Player and Volume Controller tutorials and as a result, can now play, stop and adjust the volume of a music file that is defined in the code. My apologies in advance if the questions below have been answered in the past.

However, I have searched the forums and can’t seem to find anything directly answering the two following questions:

i) What code would be required (I would assume code would only be required for the button used for pausing) for a button to pause the music playing when pressed?

ii) What code would be required (I would assume code would only be required for the button used for muting) for a button to mute the music playing when pressed?

Thanks for any and all help,
JK.

Sound.prototype.pause = function() {
	this.paused ? this.start(this.position/1000) : this.stop();
	this.paused = !this.paused;
};
Sound.prototype.mute = function() {
	if (this.muted) this.setVolume(this.volume);
	else this.volume=this.getVolume(), this.setVolume(0);
	this.muted = !this.muted;
};

example:

mySound = new Sound(this);
mySound.attachSound("sound");
mySound.start();
pauseButton.onRelease = function() {
mySound.pause();
};
muteButton.onRelease = function() {
mySound.mute();
};

:wink:

I’ll check that out asap. Thanks sooooo much!!! :beam: :).

Hi JK87 how are you
I have also got the same problem with you,
after reading this I still don’t understand

if you know how to do it, could you please tell me
it will be perfect if you can attach a FLA as a example
thank you

I’m fine thanks. I haven’t had the opportunity to test this out yet because I have been trying to help SBV in another thread. Give me a few minutes and I will see what I can come up with :).

JK.

Well, it’s certainly not trivial. Following the soundbar tutorials, you end up with a soundbar with which you can Play, Stop and Adjust the volume of a piece of music.

The Play button has this code applied to it:
[AS]on (release) {
if (_root.mySlider.complete == 1) {
_root.mySlider.mySound.start(0, 99);
}
}[/AS]

The Stop button has this code applied to it:
[AS]on (release) {
_root.mySlider.mySound.stop();
}[/AS]

But the majority of the code resides in the slider which you use to adjust the volume.

If you follow what kax said, I think you need to do two separate things to get the Pause and Mute functions working. I may not be able to get it to work but I will do my best, give me a few more minutes please :).

Note that I’m relatively new to Flash (less than a week), so I am hardly a coding expert.

No luck, sorry. I can roughly see what you need to do but I don’t know exactly how to do it. Hopefully somebody will be able to clarify this for us :).

My apologies,
JK.

thank you very much for trying to do that for me :slight_smile:

No problems. Only next time, I would like to be able to solve the problem as well :).

It’s really frustrating because I can see what you need to change in the code to suit your file but I can’t work out exactly where the code would need to go :-.

  • jk87

use this script in your buttons to pause/mute the sound:

// pause
on (release) {
_root.mySlider.mySound.pause();
}
// mute
on (release) {
_root.mySlider.mySound.mute();
}

and instead of this script…

on (release) {
if (_root.mySlider.complete == 1) {
_root.mySlider.mySound.start(0, 99);
}
}

use this…

on (release) {
if (_root.mySlider.complete == 1) {
_root.mySlider.mySound.start();
_root.mySlider.mySound.onSoundComplete = function() {
this.start();
};
}
}

that should do it… :wink:

  • open0102

i don’t know how is your set up so i can’t really help you. could you attach your .fla? :-\

Hi Kax, I really want to show you my fla file, but the file is too big to send on this sever.
but if you really kind enough to help me, I have created a fla file that have Play, Pause, Stop and Mute buttons in it, there is no code in it, because I assume that it would be easier for you to work on, as I may make a lot of mistakes and you have to modify them. it will be gratefull if you can make it work.
My apologies first if this is not a good way to ask
thank you

I am sorry why there is no option for me to attach the file

to attach a file you must use the reply form (or whatever i should call it :P). :wink:

<a href=“newreply.php?s=&action=newreply&threadid=24787”>
<img alt=“post reply button large” src=“images/post_reply.gif” border=“0” width=“90” height=“25”></a>

Thanks sooooo much kax (again :)) :thumb:.

no problem. =)

Haha go figure - neither of those work. The new play ActionScript works because it doesn’t actually change the function it just enhances it… but the ActionScript for pause and mute doesn’t work.

I think the mute could be done by using setVolume(0) when the user clicks the mute button but there is a problem with that in this case because the volume slider has mySound coded ‘inside’ it as such.

I looked in the help file of Flash MX and it doesn’t have .mute or .pause in the commands concerning sound :(. Perhaps you have to code both functions?

… either way, this has helped me improve my coding knowledge. Shame it doesn’t work though ;).

ok… here’s an example.

put an .mp3 file called sound.mp3 in the same directory than the .fla to test it. :wink: =)

Ahh… all your code was in the frame - not in the different buttons. That makes the first code you posted much easier to understand now lol.

It’s all working fine so I will toy around with it and see what I can do. Thanks sooo much (third time lucky eh? :)).

yup… i always put all my scripts within the first frames. that way i don’t have to go through all my symbols looking for a script. :stuck_out_tongue:

and you’re welcome. :wink:

by looking at your example it is much easy to understand how the code works
thank you guys :slight_smile: