I want an mp3 file to be played when a button is pressed a certain amount of times in swift - swift

I am working on a tap counter app and I need a sound to be played every thousand clicks but I could not figure out how to play it after multiple clicks in swift. If possible could someone please provide the code necessary to do so. It would be very helpful.

Set a variable as a counter = 0. Increment that counter (+= operator) every time the button is pressed. Also check to see if if counter == 1000, and if so, play MP3 and reset counter to zero.

Related

How can you check for actions (on screen buttons) during the NStimer event (SWIFT)

I am trying to program something like the old Simon memory game.
Having some issues when trying to set up the user input section which i imagined to be something like
Run through the current array for each item in 'simons memory'
Start timer
if no input for the timer duration then game over
if input correct - reset timer - continue on next item
if input incorrect - play annoying sound - end while loop - check score against hi score
and update.
Was wanting to use NSTimer but not sure how to check for input during the timer. I am a newbie to this so please be kind or not I can take it.
Thanks
use the timer to disable the input section and then move to game over
If there is input, check it in the view controller, and deal with the timer from there - to either continue, or end the game

MPMoviePlayerController repeat mode

I have used MPMovieController for video play. I need to repeat the video for user define times. So how can i check the repeat count for the specific video if i have enabled the repeatMode.
I think by using "MPMoviePlayerPlaybackDidFinishNotification" this notification function you can check count..i.e repeat mode , repeats while it's going to finish playing...& playing is finishing u can get this notification...so you can maintain your count.

iphone html 5 video - how to start from different time

What is the correct way to begin playback of a video from a specific time?
Currently, the approach we use is to check at an interval whether it's possible to seek via currentTime and then seek. The problem with this is, when the video fullscreen view pops up, it begins playback from the beginning for up to a second before seeking.
I've tried events such as onloadmetadata and canplay, but those seem to happen too early.
Added information:
It seems the very best I can do is to set a timer that tries to set currentTime repeatedly as soon as play() is called, however, this is not immediate enough. The video loads from the beginning, and after about a second, depending on the device, jumps. This is a problem for me as it provides an unsatisfactory experience to the user.
It seems like there can be no solution which does better, but I'm trying to see if there is either:
a) something clever/undocumented which I have missed which allows you to either seek before loading or otherwise indicate that the video needs to start not from 00:00 but from an arbitrary point
b) something clever which allows you to hide the video while it's playing and not display it until it has seeked (So you would see a longer delay on the phone before the fullscreen video window pops up, but it would start immediately where I need it to instead of seeking)
do something like this;
var video = document.getElementsById("video");
video.currentTime = starttimeoffset;
more Information can be found on this page dedicated to video time offset howtos
For desktop browser Chrome/Safari, you can append #t=starttimeoffsetinseconds to your video src url to make it start from certain position.
For iOS device, the best we can do is to listen for the timeupdated event, and do the seek in there. I guess this is the same as your original approach of using a timer.
-R

Make sound stop when button is pressed iOS

I have multiple buttons that play sounds using AVAudioPlayer. If you press one, and press another before the first ends, they are both playing at the same time. How would i make it so if you press two buttons, only the last pressed button's sound plays?
I don't know the exact code, but you may have to bool something or try AudioServicesDisposeSystemSoundID. It will stop the sound immediately.
Before you start the new song you have to do:
[song1 stop];
song1.currentTime = 0;
And do that for all the songs that could be possibly playing. Then you can make the new song play. (The current time sets it to start from the beginning if you play it again.) hope that helps :)

How to play infinitely overlapping sounds?

I have a button that triggers a sound on an iphone. I am using AudioUnits to minimize the latency.
Right now, if the user taps the button twice, the sound do not overlap and the first triggered sound is cut by the second sound. Is there an easy way to let the (same) sound overlapping as many times as the user taps the buttons?
Thanks.
André.
Leave the AudioUnit running continuously, using short buffers to minimize latency, and start to mix another copy of the sound into the existing stream every time the button is tapped.