On a webpage I'm using a couple of audio-tags for mouse-over sounds and a video-tag for playing a video.
Now, when the video is playing, the audio should be stopped and disabled. The audio gets triggered like this:
$(this).mouseover(function() {
$('audio#' + $(this).attr('title') + '_sound').trigger('play');
});
Now there should be added something like this, I've tried a couple of thing which none of are working:
$(this).mouseover(function() {
if($('#video') is NOT playing) {
$('audio#' + $(this).attr('title') + '_sound').trigger('play');
}
});
Anyone made something like this before?
Any help is appreciated :-)
Thanks!
On a webpage I'm using a couple of audio-tags for mouse-over sounds and a video-tag for playing a video.
Now, when the video is playing, the audio should be stopped and disabled. The audio gets triggered like this:
$(this).mouseover(function() {
$('audio#' + $(this).attr('title') + '_sound').trigger('play');
});
Now there should be added something like this, I've tried a couple of thing which none of are working:
$(this).mouseover(function() {
if($('#video') is NOT playing) {
$('audio#' + $(this).attr('title') + '_sound').trigger('play');
}
});
Anyone made something like this before?
Any help is appreciated :-)
Thanks!
Share Improve this question asked May 27, 2011 at 13:22 StefanStefan 411 silver badge2 bronze badges3 Answers
Reset to default 3HTML5 has a paused attribute.
var v = document.getElementsByTagName("video")[0];
$(this).mouseover(function() {
if(v.paused){ // checks to see if video is paused
$('audio#' + $(this).attr('title') + '_sound').trigger('play');
}
});
You should register an event listener to be called whenever the video tag's pause signal has been asserted.
var v = document.getElementsByTagName("video")[0];
v.addEventListener("pause", function() { audio.trigger("play"); }, true);
var video = document.getElementById("myVideo");
var music = document.getElementById("myMusic");
var noOverlap = setInterval(
if(myVideo.paused == false){
myMusic.pause();
}
, 1000);
This will check to see if the two are overlapping every second and by default, play the video and pause the music.