当另一个音频文件被点击时使用jQuery停止音频,同时模糊链接
Stopping audio when another audio file is clicked using jQuery while obscuring link
当按下播放时,文件。mp3应该播放,当再次点击。mp3应该停止并重置音频。
如果在声音已经播放时按下另一个播放按钮,则应该停止音频,将其时间重置为0,并播放新音频。
目标是一次只播放一个声音,这样声音就不会重叠,同时从'key'获取文件名,并在javascript/jquery中添加目录+ .mp3后。
此方法的主要目的是防止用户右键单击"另存为"而模糊mp3位置。
由于某些原因它不工作
<span class="play" key="cef83b993c716dd543b6fa4f053cc4a4">Play</span>
<br>
<span class="play" key="7a5c5d3940f65d81489a0c18f877114b">Play</span>
<script>
var currentAudio = null;
$(".play").click(function () {
if(currentAudio != null && !currentAudio.paused && currentAudio != this){
currentAudio.pause();
currentAudio.currentTime = 0;
$( this ).removeClass( "pause" );
$( this ).addClass( "play" ); // switch to play button
}
var audio = ("beats/" + $(this).attr('key') + ".mp3");
if (audio.paused) {
audio.play();
currentAudio = audio;
$( this ).addClass( "pause" ); // switch to pause button
} else {
audio.pause();
$( this ).removeClass( "pause" );
$( this ).addClass( "play" ); // switch to play button
}
});
</script>
我想象的是这样的:
$(".play").on('click',function(){
var key = $(this).attr('key');
EvalSound(key);
});
var thissound = new Audio();
var currentKey;
function EvalSound(key) {
if(currentKey !== key)
thissound.src = "http://designlab360.org/fhi/splash/dev2/audio/" + key + ".mp3";
currentKey = key;
if (thissound.paused)
thissound.play();
else
thissound.pause();
thissound.currentTime = 0;
currentPlayer = thissound;
}
见http://jsfiddle.net/sjmcpherso/pt3cx1eo/11/
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 如何使用jQuery自动打开页面上的所有链接
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- jquery动画可以通过编程链接吗
- 在单击href链接的同时下载文件
- 尽管链接成功并已成功下载,但未找到NPM模块
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 单击页面上的链接后高度发生变化
- 将纯文本URL转换为可单击链接
- 单击链接时播放音频剪辑
- 如何用一个按钮或链接切换音频播放() pause()
- 音频标签,点击链接时添加src
- 内联音频播放/暂停文本链接
- 当另一个音频文件被点击时使用jQuery停止音频,同时模糊链接
- HTML音频播放器轨道链接在新浏览器打开
- 动态添加的返回false的链接在添加音频后不起作用
- jQuery音频停止一旦链接被点击
- SoundManager2(音频播放器):检索单击的链接的ID
- 如何使用Mediaelement Player实现可点击的音频章节链接