has Iphone built in beep sound effect - objective-c

hi i need to use beep on iphone, but the only thing i have found is this
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"alert" ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
[soundPath release];
it is working and good code but i need to import the alert.wav file.But i rather do this with native (built in) sounds if there exist.
thanks for all the answers
cs.

Reading the documentation of Apple and this, I'm almost certain that you can play that wanted sound without carrying it.
You can do this:
AudioServicesPlaySystemSound(1005);
that should do.
Reference: here

Related

my aap crash on ios 7 when clicking on back button

-(IBAction)Back:(id)sender{
NSString *path = [NSString stringWithFormat:#"%#%#",
[[NSBundle mainBundle] resourcePath],
#"/Dtmf-star.wav"];
//declare a system sound id
SystemSoundID soundID;
//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);
[Buttonback setImage: nil forState:UIControlStateNormal];
int size = [PhoneUrl length];
if (size>0) {
PhoneUrl = [PhoneUrl substringToIndex:size-1];
}
dspText.text = PhoneUrl;
}
this i have done..i am able to delete one digit but if there is more than one digit application get crash...
It is working fine in ios6.
Unless you post almost the complete code, these kind of problems are really hard to solve for us. But it is propably a good idea to run the program in combination with a debug function monitoring the memory, since your problem most likely has something to do with that.

Audio Playback Not Working (AudioToolbox/AudioServices) - iPad 3

I have a short method which plays an audio notification using the AudioToolbox/AudioServices library (i've removed most of the functional code for brevity):
- (IBAction)thatWasEasy:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filePath = [mainBundle pathForResource:#"easy" ofType:#"mp3"];
NSURL *aFileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)aFileURL, &soundID) ;
AudioServicesPlaySystemSound(soundID);
}
The audio plays correctly in the simulator as well as on iPad 1 and iPad 2 devices, however on the iPad 3 (Verizon LTE version) the sound is not heard. I've checked the devices sound settings thoroughly, and also converted the audio file type to wav, and caf with no difference in behavior.
Any suggestions on troubleshooting this a bit deeper? I unfortunately do not have another iPad 3 lying around for comparison. Appreciate the help!
Figured it out. When you go to [Settings] and select [Sounds] under the [General] tab you can verify that your ringer and alerts volume level is above zero, and when moving the slider the device will chime at the newly set level. In addition you will note that all of your specific tones are enabled in the list below. This is what threw me off when checking the device settings. I launched YouTube and other applications and was able to play sound just fine.
What I didn't realize until I spoke to another guy (who knows the product a little better), is that there is another method to mute system sounds. By pressing the circle button twice an icon bar is revealed on the bottom of the screen. If you drag the icons to the right with your finger a speaker icon is revealed. This happened to be muted for some reason...presumably after I performed a system restore recently. Tap it to un-mute and your back in business. Not sure why Apple designed it this way, but it would have been helpful (and saved me a few hours of tinkering) if it had been accessible under the device settings.
I don't think you can play an mp3 file on the device using AudioServicesPlaySystemSound
AudioServicesPlaySystemSound apple document
-(void)playAif:(NSString *)filename {
// NSLog(#"play: %#", filename);
SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle]
pathForResource:filename ofType:#"aif"];
if (path) { // test for path, to guard against crashes
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; // 1
AudioSessionSetProperty (
kAudioSessionProperty_AudioCategory, // 2
sizeof (sessionCategory), // 3
&sessionCategory // 4
);
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID);
AudioServicesPlaySystemSound (soundID);
}
}

AVAudioPlayer refuses to play anything, but no error, etc

This is the simplest possible AVAudioPlayer code, and it's just failing to play anything back. No errors, nothing in the console at all, the file is definitely being found as if I change the URL string to something which isn't there, I do get a crash. What am I doing wrong here? I've tried it with and without the delegate, as well as with and without prepareToPlay, and I can't get anything out. I've tried various sound files, too. Really tearing my hair out on this one!
#implementation ViewController
- (IBAction)playSound:(id)sender
{
NSURL *soundLocation = [[NSURL alloc] initWithString:#"Lot01.wav"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundLocation error:nil];
[audioPlayer setDelegate:self];
[audioPlayer play];
}
#end
Turned out it was an issue with ARC releasing, I fixed it by adding a #property and #synthesize pair for the AVAudioPlayer in question, and declaring it as strong. It got rid of all of these errors, and played the file with no problems.
It seems like it's not correctly getting the path to your file, maybe try something like this.
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Lot01" ofType:#"wav"];
NSURL *url = [NSURL fileURLWithPath:filePath];
then init the AVAudioPlayer exactly how you were except in that case it'd be withContentsOfURL:url.

Audio and vibrate working in simulator not on ios device

First off, I'm fairly new with objective C. I want to play a sound and vibrate under a certain condition. My iPhone 4 is not on mute, I've checked case sensitivity and used both AVAudioPlay and SystemSound to try and play the file but even the vibrate will not work. AudioToobox and AVfoundation are imported in .h. The audio plays with both methods on the iOS simulator.
Heres the code using SystemSound:
if (al == 1){
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) #"Alarm", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);}
And with AVAudioPlayer:
if (al == 1) {NSString *path = [[NSBundle mainBundle] pathForResource:#"alarmtwo" ofType:#"wav"];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.numberOfLoops = 0;
theAudio.volume = 1.5;
[theAudio prepareToPlay];
[theAudio play];}
By the way, the variable al sets to 0 after it plays. Is my coding wrong to have the sound and vibrate work on the device itself? Is there a specific type of .wav file that needs to be played? Any help would be appreciated.
I was running into this same issue. There is actually a second volume setting specially for alerts that at least in my case was set to mute, even though my regular volume was up. Take a look under the sounds menu in the Settings app on the device and turn that up.
You probably don't want to use the alerts for an actual released app though if it is important that the sound actually play, since it will require users to make sure this separate audio setting is up.

maximize the sound effect in iPhone game by code?

I just built a game. It already has all the sounds. But for some reasons the sound effect of the click button is still small. How could I maximize the volume. I am not sure it is because of the quality of the sound files itself or because I din't increase the volume by code? could you guys help me out. Thanks in advance. Here is my code.
-(void) play
{
NSString *path = [NSString stringWithFormat:#"%#%#",[[NSBundle mainBundle] resourcePath],#"/menu_button_2.wav"];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory :NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath ,&soundID);
AudioServicesPlaySystemSound(soundID);
//AudioServicesDisposeSystemSoundID (soundID);
}
From the System Sound Services Reference:
The interface does not provide level, positioning, or timing control
I would assume level implies volume.
If you use AVAudioPlayer you can set the volume from 0.0 to 1.0 with the volume property, but I am sure that opens up a new set of problem tradeoffs.