UILocalNotification Or EventKIt - iphone

Is there a way to trigger some kind of task on the base of date event .My problem is that i want to play sound (alarm) on specific date it does work fine by using UILocalNotification, but it plays s short sound , and i want to play an infinite sound instead of .How can i achieve this goal ..
waiting for your early response.
Thanks

The apple documentation of UILocalNotification states that the soundName property will play for a maximum of 30 seconds only.
Sounds that lasts longer than 30 seconds are ignored and the default sound is played instead.
While adding the custom sound make sure the sound is in the correct format (linear PCM or IMA4)
You can convert from wav and mp3 using:
afconvert -f caff -d LEI16#44100 -c 1 in.wav out.caf
In case if u were wondering what is afcomvert ..it's nothing but command line program
Caf is container format..
Sometimes emulator won't play the custom sound but device does.

You can schedule a custom sound using the soundName property of UILocalNotification, but it can't be infinite. You could use the repeatInterval property to play the alert again, making it seem infinite...

Related

Assign alert tone for UILocalNotification from available sounds in iphone

I am working on an app that used UILocalNotification. I wanted to select sound from default sounds that came with iPhone. How can i list down sounds for assign as the alert tone.
There is one standard sound for notification from system (UILocalNotificationDefaultSoundName). You can play any custom sound shorter than 30 seconds. So, if you can download any native sound from ios from anywhere, you will be able to use it as custom sound. Documentation

Choose custom sound for local notifications

How do you change the sound that plays for local notifications? I use the code below to play the default sound:
notif.soundName = UILocalNotificationDefaultSoundName;
So, I tried this below, and it didn't work. What should I do? Thanks for your help!
notif.soundName = #"sound.caf";
You can convert from wav and mp3 using:
afconvert -f caff -d LEI16#44100 -c 1 in.wav out.caf
That should work. Make sure the sound is actually in your app’s bundle, is in the correct format (linear PCM or IMA4—pretty much anywhere that explains how to convert sounds for iOS will tell you how to do that), and is under 30 seconds.
I also tried to convert mp3 to caf using command below:
afconvert clockalarm.mp3 clockalarm.caf -d ima4 -f caff -v
One lesson here: I spent several hours to struggle with the sound of local notification. Tried to convert with different bitrate and format. But finally I found that there must be a defect with the iOS 6.1 emulator. I deployed the code to device, it works well, but on emulator, does not have any sound.
I ran into all of these problems (thanks for the answers) and was able to solve the problem by converting from .wav to .caf (sans 6.1 simulator). The last bit I needed was to make sure the .caf was in the my app's bundle. To confirm/correct this...
Right click the file in the "Project Navigator", select "Show File Inspector" and make sure the file has a check mark next to your project in the "Target Membership" area. In my case "LocalNotificationExampleTests" was the only item checked. Checking "LocalNotificationExample" fixed my lack of sound on the device.
For Swift 3 use UNNotificationSound.init for the notif object in notification scheduling function.
Here's a Swift 3 example:
func scheduleNotifications(inSeconds: TimeInterval, completion: #escaping (_ Success: Bool) ->()){
...
notif.sound = UNNotificationSound.init(named: "CustomSound.mp3")
...
}
Final note, according to Apple: "The sound file must be contained in the app’s bundle or in the Library/Sounds folder of the app's data container. If files exist in both locations then the file in ~/Library/Sounds will be preferred."
Swift 5.1
How do you change the sound that plays for local notifications. I use the code below to play the default sound:
content.sound = UNNotificationSound.init(named: UNNotificationSoundName(rawValue: "Sound_Name.mp3"))

Is it possible to play just a part of an mp3 file with AVAudioPlayer? If yes, how?

Hi I have a locally stored 5:00 minutes mp3 files in my iPhone app.
I would like to know if it is possible to play just an interval from that file using AVAudioPlayer after it is readyToPlay, lets say from 0:25 to 1:34.
If it is possible how can I achieve that?
I know I can move the playhead cursor using setCurrentTime: but how do I let the AVAudioPlayer know how many seconds it should play from that currentTime.
Any help is highly appreciated.
You will need to set a timer which will stop that playing after particular time interval.
#Horatiu you can use NSTimer to schedule it for a particular time interval after you have use setCurrentTime: method, and in the selector method of the NSTimer you can make the audioPlayer stop.
Fire a timer when you start playing the file. When the required time is reached pause or stop the player

Best way to play different sounds one at a time on iphone?

I have a bunch of sounds I want to play. Right now I'm using AVAudioPlayer. A new sound should start when the user clicks a button. The url property of AVAudioPlayer is read-only. I'd rather not have to release and re-alloc the object every time I want a new sound played. What would be the best way to do this? Is there a different class I need to use?
The absolute easiest way to play sound is Playing UI Sound Effects or Invoking Vibration Using System Sound Services. Essentially you call AudioServicesCreateSystemSoundID() and AudioServicesPlaySystemSound(). Creating a system sound is relatively expensive and playback stops when it's disposed with AudioServicesDisposeSystemSoundID() anyway, so you really want to cache them:
Create them at app launch (or possibly the first time the sound is played). You can keep them in an NSDictionary keyed by sound file name and store the sound ID in an NSValue, or so.
If you can be bothered, dispose them when your app exits, is backgrounded, or on a memory warning.
The biggest caveat is that only a few sound formats are supported for "system sounds"; apple seems to recommend IMA4 (afconvert -f caff -d ima4 input.file output.caf and optionally -c 1 if you're happy with mono).
That said, it's pretty much perfect for playing short sounds provided you don't mind one-at-a-time sounds (it restarts playback if you play a sound while it's already playing). I suspect it's also played directly by the kernel (you can set a flag to make it continue playback when your app exits), which probably means it's more efficient CPU-wise. It might mix with sounds played by AVAudioPlayer.

Playing portion of an audio file on iPhone

Does anyone knows how to play a portion of a sound file on the iPhone?
Using the SDK, or any other library (Cocos Desnhion...).
I know how to play an entire sound, but not an exact portion of it (eg. from 2,5ms to 6ms).
Thanks!
Vincent
AVAudioPlayer has a currentTime property. Set it to start playing the file at a specific time mark and then watch its progress to stop playing when it reaches a desired mark.