admin管理员组文章数量:1022424
Hi im trying to have a song play when i click and pause when i click it again however it only seems to be playing this is the code below:
Javascript
function StartOrStop(audioFile)
{
var audie = document.getElementById("myAudio");
if(!audie.src)
audie.src = audioFile;
if(audie.paused == false)
{
audie.pause();
}
else
{
audie.play();
}
}
HTML5
<img src="images/play.png" alt="Play Button width="57" height="50" onclick="StartOrStop('RWY.mp3')" >
Any suggestion on how i can fix it ?
Hi im trying to have a song play when i click and pause when i click it again however it only seems to be playing this is the code below:
Javascript
function StartOrStop(audioFile)
{
var audie = document.getElementById("myAudio");
if(!audie.src)
audie.src = audioFile;
if(audie.paused == false)
{
audie.pause();
}
else
{
audie.play();
}
}
HTML5
<img src="images/play.png" alt="Play Button width="57" height="50" onclick="StartOrStop('RWY.mp3')" >
Any suggestion on how i can fix it ?
Share Improve this question edited Mar 23, 2013 at 20:03 user2202031 asked Mar 23, 2013 at 12:33 user2202031user2202031 251 gold badge1 silver badge7 bronze badges1 Answer
Reset to default 2When ever you click the image
, it calls the StartOrStop
function, this will cause the src
of video set again thus cause paused
to be true
so you can't pause the video but just play it again.
This version should work:
HTML:
<img src="images/play.png" alt="Play Button" width="57" height="50" onclick="StartOrStop('RWY.mp3')">
<audio id="myAudio"></audio>
Javascript:
function StartOrStop(audioFile) {
var audie = document.getElementById("myAudio");
if (!audie.src || audie.src !== audioFile) audie.src = audioFile; // check if there's a src already and if the current src is not the same with the new one, change it. Or don't do anything.
if (audie.paused == false)
audie.pause();
else
audie.play();
}
Fiddle: http://jsfiddle/QCGYP/4/
Hi im trying to have a song play when i click and pause when i click it again however it only seems to be playing this is the code below:
Javascript
function StartOrStop(audioFile)
{
var audie = document.getElementById("myAudio");
if(!audie.src)
audie.src = audioFile;
if(audie.paused == false)
{
audie.pause();
}
else
{
audie.play();
}
}
HTML5
<img src="images/play.png" alt="Play Button width="57" height="50" onclick="StartOrStop('RWY.mp3')" >
Any suggestion on how i can fix it ?
Hi im trying to have a song play when i click and pause when i click it again however it only seems to be playing this is the code below:
Javascript
function StartOrStop(audioFile)
{
var audie = document.getElementById("myAudio");
if(!audie.src)
audie.src = audioFile;
if(audie.paused == false)
{
audie.pause();
}
else
{
audie.play();
}
}
HTML5
<img src="images/play.png" alt="Play Button width="57" height="50" onclick="StartOrStop('RWY.mp3')" >
Any suggestion on how i can fix it ?
Share Improve this question edited Mar 23, 2013 at 20:03 user2202031 asked Mar 23, 2013 at 12:33 user2202031user2202031 251 gold badge1 silver badge7 bronze badges1 Answer
Reset to default 2When ever you click the image
, it calls the StartOrStop
function, this will cause the src
of video set again thus cause paused
to be true
so you can't pause the video but just play it again.
This version should work:
HTML:
<img src="images/play.png" alt="Play Button" width="57" height="50" onclick="StartOrStop('RWY.mp3')">
<audio id="myAudio"></audio>
Javascript:
function StartOrStop(audioFile) {
var audie = document.getElementById("myAudio");
if (!audie.src || audie.src !== audioFile) audie.src = audioFile; // check if there's a src already and if the current src is not the same with the new one, change it. Or don't do anything.
if (audie.paused == false)
audie.pause();
else
audie.play();
}
Fiddle: http://jsfiddle/QCGYP/4/
本文标签: htmlJavascript play and pause a song with one click on the same imageStack Overflow
版权声明:本文标题:html - Javascript play and pause a song with one click on the same image - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745496682a2153197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论