I have an event where I need to play a mp3/wav sound every time a certain condition is verified. Is there a way to play it cross-browser, also even if I open android browser on a tablet?
Actually I am using a javascript plugin called ionSound but looks like it doesn't work under android's tabled..
Like:
jQuery.ajax({
type: "GET",
dataType: "json",
url: "./getData.php?idx="+id,
success: function(data) {
if (data.length > 0) {
// alert('Gotta play sound...');
dataFound = true;
$.ionSound({
sounds: [ "woop_woop" ],
path: "../../images/"
});
$.ionSound.play("woop_woop");
// alert('Played sound right now...');
} else {
dataFound = false;
}
}
});
Thanks in advance to all!
Cheers, Luigi
I'm picking back this question again... I figured out on some platforms it doesn't really play sound... for example on another desktop PC with Chrome it doesn't play audio, neither on another tablet...I think it's due of browser's version... so is there a pure javascript way to just play an audio like a little mp3 or wav from code?..
Thanks in advance! Cheers Luigi
I have an event where I need to play a mp3/wav sound every time a certain condition is verified. Is there a way to play it cross-browser, also even if I open android browser on a tablet?
Actually I am using a javascript plugin called ionSound but looks like it doesn't work under android's tabled..
Like:
jQuery.ajax({
type: "GET",
dataType: "json",
url: "./getData.php?idx="+id,
success: function(data) {
if (data.length > 0) {
// alert('Gotta play sound...');
dataFound = true;
$.ionSound({
sounds: [ "woop_woop" ],
path: "../../images/"
});
$.ionSound.play("woop_woop");
// alert('Played sound right now...');
} else {
dataFound = false;
}
}
});
Thanks in advance to all!
Cheers, Luigi
I'm picking back this question again... I figured out on some platforms it doesn't really play sound... for example on another desktop PC with Chrome it doesn't play audio, neither on another tablet...I think it's due of browser's version... so is there a pure javascript way to just play an audio like a little mp3 or wav from code?..
Thanks in advance! Cheers Luigi
Share Improve this question edited Mar 21, 2014 at 2:30 Bill the Lizard 406k211 gold badges572 silver badges889 bronze badges asked Feb 14, 2014 at 9:33 LuiginoLuigino 7793 gold badges9 silver badges30 bronze badges1 Answer
Reset to default 21Create an Audio
object and play
it!
The link Audio
takes in the constructor may be from any source.
var audio = new Audio('audio_file.mp3');
audio.play()