M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

success / error sound

hi,

I have an app where I need to be able to play an error sound or an success sound based on whether I am able to successfully read an NFC Tag.

How do I play success / error notification sounds? Like for example there is error.wav in windows....or the exclamation sound.

Just playing Beeps won't do as it will sound the same - for success and failure.

Thanks,
M&M

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

success / error sound

hi,

I think I can use the Cordova Local-Notification Plugin for playing the sounds as well.

Thanks,
M&M

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

success / error sound

oops I cannot just play the sound without displaying the notification :-O

So this question is still open ",)

Any tips will be helpful

Cheers,
M&M

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

success / error sound

Hi M&M,

You can use HTML5 audio tag for it.

Following solution is how to add it dynamically(via JS code) and how to start/stop play the sound:

  1. Add new JS asset. And populate it with following js code:

    precode

    var onLoad = function() {
    var audioText = '<audio id="yourAudio" controls=""><source src="http:&#47;&#47;demos&#46;w3avenue&#46;com/html5-unleashed-tips-tricks-and-techniques/demo-audio&#46;ogg"><source></audio>';
    var audio = jQuery(audioText);
    jQuery("body")&#46;append(audio);
    console&#46;log("load");

    };
    jQuery(window)&#46;bind("load", onLoad);

    function PlayTrack(src) {
    var au = jQuery("#yourAudio");
    au&#46;attr("src", src);

    if (au[0] && au[0]&#46;play) au[0]&#46;play();
    };

    function StopPlayTrack() {
    var au = jQuery("#yourAudio");

    if (au[0] && au[0]&#46;play) au[0]&#46;pause();
    };

    /code/pre

  2. When you need to play new sound use following JS code:

    pre

    PlayTrack("http:&#47;&#47;demos&#46;w3avenue&#46;com/html5-unleashed-tips-tricks-and-techniques/demo-audio&#46;mp3")

    /pre

  3. To stop current played track you can use following JS code:

    pre

    StopPlayTrack();

    /pre

    Regards.

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

success / error sound

This works GREAT!!
Thanks.
For local sound files.
In the SOURCE View. Upload your sound file (eg. Bell.mp3) into say.
WEB_RESOURCES -files -resources
Change the onLoad = function() to.
code
var onLoad = function() {
var audioText = '<audio id="yourAudio" controls=""><source src="files/resources/Bell&#46;mp3"><source></audio>';
var audio = jQuery(audioText);
jQuery("body")&#46;append(audio);
console&#46;log("load");
};
/code

And Play sound by calling like this.
code
PlayTrack("files/resources/Bell&#46;mp3");
/code

Works in App and Browser Tester.

Return to “Issues”