Page 1 of 1

success / error sound

Posted: Thu Jan 01, 2015 4:35 pm
by M&M

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


success / error sound

Posted: Thu Jan 01, 2015 5:30 pm
by M&M

hi,

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

Thanks,
M&M


success / error sound

Posted: Thu Jan 01, 2015 6:07 pm
by M&M

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


success / error sound

Posted: Thu Jan 01, 2015 10:37 pm
by Yurii Orishchuk

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.


success / error sound

Posted: Sat Feb 28, 2015 6:11 pm
by Emmz

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.