播放声音上点击 [英] play sound on click

查看:167
本文介绍了播放声音上点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也问了几个地方这个问题,但还没有找到或接收答案。我是一个code新手,所以任何帮助将大大AP preciated。

i have asked this question in a couple of places, but have yet to find or receive an answer. i am a code newbie, so any help would be greatly appreciated.

我使用在页面的JavaScript的一些我的网页播放声音上点击其中一个循环依托轨道练习秤/主音吉他到图像。

i am using in-page javascript on some of my pages to play a sound on clicking an image which loops a backing track to practise scales / lead guitar to.

这里的脚本:

<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"true\" />";
}
</script>
<span id="dummy"></span>

和这里就是我怎么叫它为每个图像/ MP3:

and here's how i'm calling it for each image / mp3:

<p><a title="Play file" href="#" onclick="playSound('mp3 url');"><img title="Play" src="play button url" alt="Play" width="48" height="48" /></a>  Blues in <strong>C</strong> : backing for lead melody. Chords: C,F, G</p>

我的第一个问题 - 轨道不循环 - ?是有什么错剧本

my first question - the track isn't looping - is there something wrong with the script?

我的第二个问题 - 如何扩展功能,以便在点击PNG发挥它换为另一个文件 - 停止按钮 - 这会停止点击时循环

my second question - how do i extend the function so that on clicking the png to play the file it is swapped for another - stop button - which stops the loop when clicked.

千恩万谢,扬

推荐答案

欢迎到堆栈溢出。

听起来嵌入到网页中是一个非常棘手的问题,并得到一个解决方案,将在所有浏览器和移动设备上工作,是一个真正的挑战。

Embedding sounds into web pages is a really tricky business and getting a solution that will work across all browsers and on mobile devices is a real challenge.

幸运的是,库,您可以使用,使嵌入,播放,循环,MP3音乐的切换非常非常容易。

Fortunately there are libraries that you can use to make the embedding, playing, looping, switching of mp3s much, much easier.

我建议寻找到 Soundmanager2 ,你得到的太多进一步到这个项目之前,看它是否可以为您节省大量的编码时间,精力和挫折的!

I'd recommend looking into Soundmanager2, before you get too much further into this project to see if it could save you a lot of coding time, effort and frustration!

这篇关于播放声音上点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆