admin管理员组文章数量:1425786
I've seen many web pages with a simple sound on /sound off button which plays music or some mp3 file when you press sound on and turns it off when you press off.
How do I do that?
Hi, I wasn't planning on using Flash -- if there is a standard plugin I could use and then make modification to the script, that'd be cool.
I'm open to whatever is the "standard" way to do it.
I've seen many web pages with a simple sound on /sound off button which plays music or some mp3 file when you press sound on and turns it off when you press off.
How do I do that?
Hi, I wasn't planning on using Flash -- if there is a standard plugin I could use and then make modification to the script, that'd be cool.
I'm open to whatever is the "standard" way to do it.
Share Improve this question edited May 27, 2009 at 0:59 Satchel asked May 25, 2009 at 6:34 SatchelSatchel 16.7k23 gold badges108 silver badges194 bronze badges 1- Hi, all, thanks for the answers -- I'm not doing it in flash. I just grabbed Google's sound-player script and am using that! – Satchel Commented Jun 23, 2009 at 20:20
5 Answers
Reset to default 1Here's the proper way to do it in AS3.
Initialization:
var sound:Sound;
var channel:SoundChannel;
var pos:Number;
var numLoops:Number = 0; // 0 to loop forever
sound = new Sound();
sound.load( new URLRequest("song.mp3") );
channel = sound.play( 0, numLoops );
Stop playback:
pos = channel.position;
channel.stop();
Start playback:
channel = sound.play( pos, numLoops );
It's true that you could toggle the volume to zero and back, but this leaves needless overhead, and when you restart the sound it will have advanced from where you "stopped" it.
I used google and then I used pixel1 standalone
You can try embed my Javascript SoundPlayer and see if that works out for you. Its easy to use, just copy the code below into your webpage.
<script language="javascript" type="text/javascript" src="http://lablogic/scripts/soundplayer/audio_o.js"></script>
<a href="#" onclick='play("your-sound-file.mp3")'>PLAY</a>
<a href="#" onclick='stop("your-sound-file.mp3")'>STOP</a>
just change "your-sound-file.mp3" to the url or location of your sound file. It should work in most browser and most sound format. If it doesnt work I would really like to get feedback, so I can improve it even more. You can try out the script here to see if it works first: free javascript sound player
Are you using Flash? In that case you can do it like this:
stopAllSounds();
or
theSound.stop(["id"]);
Assuming you are using Flash as above.
AS2
stopAllSounds();
AS3
var xf:SoundTransform = SoundMixer.soundTransform;
xf.volume = 0;
SoundMixer.soundTransform = xf;
本文标签: javascriptHow do I create a quotsound on sound offquot buttonStack Overflow
版权声明:本文标题:javascript - How do I create a "sound on sound off" button? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745392646a2656669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论