- This topic has 22 replies, 4 voices, and was last updated 10 years, 6 months ago by Code_A.
-
AuthorPosts
-
falloffalotMemberOk guys I am finally getting closer to completing my App and just adding the finishing touches and stumbled across a little problem.
I know there are other posts that touch on this topic but none of them seem to help!I have my stopwatch page with a fully functioning stopwatch with Start/Stop/Splits & Reset buttons which I have created as image buttons with a little help from Photoshop.
I have been trying for almost a week trying to get each button to simply “bleep” when pressed.
Each of the 3 buttons is a single image:
I have used “On Click” command using JS to “findTime()”
Any ideas how to add a “beep” each time the buttons are pressed?Thanks guys
BrandonMemberyou can use the phonegap api:
navigator.notification.beep(1);
Two notes from the Docs:
Android Quirks
Android plays the default Notification ringtone specified under the Settings/Sound & Display panel.
iOS QuirksIgnores the beep count argument.
The iPhone does not feature a native beep API.
Cordova implements beeps by playing an audio file via the media API.
The app must provide a file with the desired beep tone.
This file must be less than 30 seconds long, located in the www root directory, and must be named beep.wav.
falloffalotMemberHi Brandon, thanks for help as always.
Only problem I now have is….I have no idea what you have just said.
Is there not and easy way to add a simple sound to an On Click command?If not…do you awesome guys at MobiOne think it would be an extremely useful widget?
BrandonMemberYou could just play an audio file.
Or if you wanted something different, instead of a beep use a vibrate!
navigator.notification.vibrate(500); //increase time for longer vibrate
falloffalotMemberThis app will be for iPad only due to the amount of data the user has to input, although using vibrate is a great idea, it won’t work on the iPad :/
I have tried using the audio player widget but can’t seem to get this to work either.
falloffalotMemberOk, audio widget “beep02.mp3” “onclick” works perfectly, however is there a way to connect this widget to the Start/Stop button so each time I select Stop/Start button “findTime()” still works and the beep can be heard?
Have tried adding “audio1.play()” to the “findTime()”on Click and nothing can be heard.
Am I doing something stupid again 😛I am only focusing on IOS Ipad platform for the moment if it helps.
falloffalotMemberSorry for the multiple posts but, there is some kind pf progress…!
The problem appears to be with multiple lines of code in the “On Click” run javasript code.
I am still learning JS so this may seem pretty basic to some of you.
If I only have the “findTIME()” line the stopwatch works with no sound
If I only have the “AudioPlayerWidget.active.play();” line the stopwatch doesn’t work but “bleeps”
If I have both lines, the stopwatch works but without sound.findTIME()
AudioPlayerWidget.active.play();What do I need to do to get both lines working together?
Code_AMemberLogically, the way you are doing it should work. There may be something within your findTIME() function that is causing the code to stop executing or returning as expected. I would recommend putting in an alert statement at the end of your findTIME() function to make sure it is executing all the way to the end.
Also, if you have the audio call after the findTIME() function, it will not play until the other function has completed its execution, so there might be a slight delay depending on how much code you are running in findTIME(). I would suggest swapping the two lines of code so that the sound executes first (this may help the other issue too).
falloffalotMemberHum…..have tried this script in every way I can think of or found using a popular search engine????
Which every is the first to be read in the script is the one that functions, just can’t seam to get both working in sync!
Code_AMemberHere is an example file that I put together to test your situation. I am not sure how closely it mimics what you are doing, but I am calling a function within the _custom.js from the OnClick event and playing audio (before and after) the function is called. Take a look and see if this is what you are trying to do.
Attachments:
You must be logged in to view attached files.
falloffalotMemberHey Code A
Thanks loads for the help, but I can’t seem to get that working in my app either.
Would you mind if I send you the files to see if you can figure it out, I’ve exhausted every possible thing i can think of!
Code_AMemberCan you post the code for your findTIME() function? I have a feeling there may be something going on in there that is causing the issue. I can drop it in my sample to see if I can recreate the issue.
TurgutGuneysuMemberHi falloffalot
Don’t want to muddy the waters but when I read that you were new to JS and saw the two function calls back to back, it reminded me of my troubles and trials with JS and its asynch execution of functions.
If there is any execution dependency between these functions, you might want to look into callback() option to control the execution sequence.
Another way to do the same is via this construct: firstFunction(function(){secondFunction()});
This will execute secondFunction() only after the firstFunction() finishes.
Good luck.
Turgut
Code_AMember@tguneysu
Funny you should mention that. I was actually going to suggest putting the function call inside a short timer to delay the call to see if that helped. I like your callback solution better as it is a bit more elegant.
falloffalotMember@tguneysu
Would you mind showing how I would execute this function please?
The two functions are:AudioPlayerWidget.active.play();
&
findTIME();Great help as usual guys 🙂
-
AuthorPosts