alarm iphone sdk - iphone

I'm trying to make alarm in my app. I made UILocalNotification and it works fine. But i need to set a mp3 song as a sound of my notification and it is not working
Here is some code
NSString *filePath = [DOCUMENTS stringByAppendingPathComponent:#"personal.mp3"];
//NSLog(#"%#",filePath);
UILocalNotification *localNotif = [[UILocalNotification alloc]init];
localNotif.fireDate = alarmPicker.date;
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = #"Alarm";
localNotif.alertAction = #"View";
localNotif.soundName = filePath;
localNotif.applicationIconBadgeNumber = 1;
//localNotif.repeatInterval = NSYearCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
Should I add framework or what i should do? right now it is not playing my mp3. Thanks

UILocation notification does not support .mp3 these are the files supported
Because custom alert sounds are played by the iOS system-sound
facility, they must be in one of the following audio data formats:
Linear PCM MA4 (IMA/ADPCM) µLaw aLaw You can package the audio data in
an aiff, wav, or caf file. Then, in Xcode, add the sound file to your
project as a nonlocalized resource of the application bundle.
Please see the answer for this question link
Also see this Preparing Custom Alert Sounds
EDIT :ADDING ANSWER FOR DURATION
You can inspect a sound to determine its data format by opening it in
QuickTime Player and choosing Show Movie Inspector from the Movie
menu.
Custom sounds must be under 30 seconds when played. If a custom sound
is over that limit, the default system sound is played instead.
You can use Audio editor/converter to trim your song
Switch
WavePad
Audacity

Related

Why are my local notifications not having sound on by default in iOS 7?

My app uses geofencing and sends a notification.
By default, sounds are off in Settings - Notifications for the app.
iOS 7 to be precise.
Does anyone know how to fix this?
Here is the code responsible for this:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [NSDate dateWithTimeInterval:5 sinceDate:[NSDate date]];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithFormat:#"You are near %#. Don't forget to check in!",place.name];
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
If the sound is turned off for your app in the Settings app, then your notification will not play any sound. The user does not allow you to do that.
If the sound is not turned off in the Settings app, that code that you posted should work.
Also if the user set the ringer switch off, then there will be no sound played.
Have you set the applicationIconBadgeNumber in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions?
Comment this code, and try again.....I don't why, but I got the same problem. After I commented this line, my app works correctly.

Local Notification Alert Timing

notificaiton = [[UILocalNotification alloc] init];
notificaiton.fireDate = [NSDate Date];
notificaiton.repeatInterval = 0;
notificaiton.alertBody = #"Alarm";
notificaiton.timeZone = [NSTimeZone defaultTimeZone];
notificaiton.repeatCalendar = [NSCalendar currentCalendar
notificaiton.soundName = #"Alarm.wav"
[[UIApplication sharedApplication] scheduleLocalNotification:notificaiton];
my question is ,
Local Notification alert stay only for few seconds but, is it possible, local notification alert stay for few minutes?
please any body has answer
Thanks, In Advance
No it is not possible to customize the AlertView and its timings. System does it and we don't have any control over it. We can only customize, the alertbody and title of the action button.
Configure the substance of the notification: alert, icon badge number, and sound.
The alert has a property for the message (the alertBody property) and
for the title of the action button or slider (alertAction); both of
these string values can be internationalized for the user’s current
language preference.
if you mean that you need to play notification sound more than 30 sec ??? then it is not possible.
you wrote that Local Notification alert stay only for few seconds but check proper that, this stay as per your sound file length.
and this sound file Must be maximum 30 sec in length.
if you will try to give soundName more than 30 sec. then it will play default sound in notification.
find this line
"Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead." into apple notification doc.

How to run command NSLog(#"Alert display...") immidiately when alert Local Notifications show?

How to run command NSLog(#"Alert display...") immidiately when alert Local Notifications show?...I'm creating a alarm clock in iphone, I want to play a music at that time (at alert Local Notifications display)! I'm going to use AVPlayer to play music form ipod library in iphone! But I can't do it. Can you help me! Thanks!
You can't execute your code when LocalNotification pops up if your app is in background and suspended. What you can do is assign you music file to soundName property, but note that your sound must not be longer then 30 secs. Here is the code:
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.soundName = #"yourMusicFile.caf";
Of course, if your app isn't suspended you can play music using AVAudioPlayer...

playing a video with MPMoviePlayerController while recording with AudioQueue

i'm developing an app which requires to play a video from an URL using MPMoviePlayerController while acquiring audio samples using AudioQueue from the microphone to further analyze them.
The problem is that I cannot record when the video starts playing (and also when it finishes). Simply the audio sampling stops. Instead, if I disable the video play, audio recording goes well.
I've tried setting up an AudioSession with property kAudioSessionProperty_OverrideCategoryMixWithOthers but with no success (it returns error). Moreover I think that it's useless setting a property in AudioSession when using AudioQueue. Even setting useApplicationAudioSession = NO for MPMoviePlayerController does not give any help.
Hereby the core code where the player is created:
audioManager = [[AudioController alloc] init];
//setting AudioQueue: audio buffer, sample rate, format ID (PCM), bits per channel
audioManager.delegate = self;
[audioManager startAudioRecording]; //starts recording with AudioQueue
self.playerVC = [[[MPMoviePlayerController alloc] init] autorelease];
layerVC.view.frame = self.viewPlayer.bounds;
[self.viewPlayer addSubview:playerVC.view];
playerVC.useApplicationAudioSession = YES; //if NO nothing changes
[playerVC setContentURL:[NSURL URLWithString:#"http://www......."]];
[playerVC prepareToPlay];
[playerVC play];
You're on the right way.
First, set the kAudioSessionProperty_OverrideCategoryMixWithOther to true. This will allow your app's sound mixes with sounds from another apps.
UInt32 allowMixing = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
After that, you will need to set MPMoviePlayerController to not use your app's AudioSession:
[yourMPMoviePlayerControllerInstance setUseApplicationAudioSession:NO];

iOS 4.3, iPhone 4 not playing custom sound with UILocalNotification

There are posts similar to mine, but I have not found one exactly like it. Here is what happens:
In my app I schedule a local notification:
UIApplication* app = [UIApplication sharedApplication];
[app cancelAllLocalNotifications];
UILocalNotification *localNotif = [[ UILocalNotification alloc ] init];
NSDate *date = [ [[ NSDate alloc] initWithTimeIntervalSinceNow:30 ] autorelease ];
if (localNotif == nil) {
return;
}
localNotif.fireDate = date;
localNotif.alertBody = #"Nearing Return Location!";
localNotif.alertAction = #"Ok";
localNotif.soundName = #"2_bubble_wrap.caf";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
Which works just fine in iOS 5. In iOS 4.3 I took care to make sure that the sound was on and loud before testing. Naturally the file is less than 30 seconds duration. When it triggers on the iPhone 4, I got no sound, just the alert box. When I retested with the default sound, it played that with the notification. When I replaced the .caf file name with gibberish, it also played the default sound, so it knew my file was there just did not play it. When I run it in the iOS 4.3 simulator it does play my .caf sound. I am losing it. Any ideas anyone?
Greg
-
Simulator != Device especially when you play media files, as your Mac supports more codecs than iPhones do. Checking that your caf file is encoded the way the iPhone needs it and correcting any issues with encoding may solve the problem.