I having working on a timer application since last 3 to 4 months (when there was no sign of iOS 6) but due to some issues could not complete it. Now since the advent of iOS 6.. I am getting error in my code. I recently downloaded the xcode 4.5 and iOS 6 SDK (within it). Now when I run the app. It crashes on different occasions. Sometimes crashes right when it is started. Some times no crashes at all.
Sometimes give me SGBRT error. Sometimes Bad_exc error(memory error). I don't know how to handle this. I have downloaded the iOS 5.1 simulator and on that when i run the app. No crashes at all but when I run the app on iOS 6 simulator. Wham! it crashes right away.
I am in dire need of guidance. Anyone who has experienced the same error and got it troubleshoot please help me too.
Thanks in Advance
Fahad.
- P.S. I added breakpoints to detect the errors and I was able to catch only one but could not understand why I got this error. Here is the code:
-(void) playAppSound:(NSString *) fName withExt:(NSString *) ext{
NSString *path = [[NSBundle mainBundle] pathForResource : fName ofType :ext];
if ([[NSFileManager defaultManager] fileExistsAtPath : path])
{
NSURL *pathURL = [[NSBundle mainBundle] URLForResource:fName withExtension:ext];
// Instantiates the AVAudioPlayer object, initializing it with the sound
if(self.appSoundPlayer)
{
if([self.appSoundPlayer isPlaying])
{
[self.appSoundPlayer stop];
[self.appSoundPlayer release];
}
}
//Thread breaks down in the next line self. appSoundPlayer...
self.appSoundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: pathURL error: nil] ;
//self.appSoundPlayer.numberOfLoops = 1;
[appSoundPlayer setDelegate:self];
[appSoundPlayer prepareToPlay];
//[appSoundPlayer setVolume:1.0];
[appSoundPlayer play];
}
else{
// NSLog(#"error, file not found: %#", path);
}
}
Check Framework versions (SDK 5 <- wrong, SDK6 <-right)
Related
I'm trying to play a sound when a button is clicked. First, I imported the AudioToolbox in the header file, then added the code into the IBAction that fires when the button is pressed, like so:
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)button1:(id)sender {
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"mySong" ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
}
I even threw an NSLog in the method to make sure it's firing. It is. I also but in a foo path in the string to see if it would crash, it did. I made sure that I dragged and dropped the short sound file into the app as well. Tested my speakers, tested audio on the device simulator by going to youtube on the simulator, everything. I can't figure out what I'm doing wrong.
When I changed the code to this:
- (IBAction)button1:(id)sender {
AVAudioPlayer *testAudioPlayer;
// *** Implementation... ***
// Load the audio data
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"3" ofType:#"wav"];
NSData *sampleData = [[NSData alloc] initWithContentsOfFile:soundFilePath];
NSError *audioError = nil;
// Set up the audio player
testAudioPlayer = [[AVAudioPlayer alloc] initWithData:sampleData error:&audioError];
if(audioError != nil) {
NSLog(#"An audio error occurred: \"%#\"", audioError);
}
else {
[testAudioPlayer setNumberOfLoops: -1];
[testAudioPlayer play];
}}
I get the error: WARNING: 137: Error '!dat' trying to set the (null) audio devices' sample rate
Hi as per you question can you please check whether you audio file is present in you project folder.It might happen that u have forgotten to checkmark "copy item if needed" so it might not be there in your project file.
You can also play sounds provided in device. Visit the below link it will be helpful.
https://github.com/TUNER88/iOSSystemSoundsLibrary
I've tested your code and it working fine and not getting crashed. Here's what I did.
As said in #matt's comment, sound playback fails in the Simulator. I had this problem when trying to play back a video.
The funny part is that sound plays just fine for the same video inside the Photos app.
I have developed an app that plays audio files with some voices recordings. When I debug it I have no problems with it, when I download it from the AppStore it works perfectly, my friends use it and they haven't got any problem with the app, but a few people from all over the world have contacted me to tell me that the app doesn't sound.
It is very strange because they tell me that the sound of the bell (mp3 44100Hz, mono, 128kbps) that plays first sounds but the voices (mp3 44100Hz, stereo, 96kbps) don't sound. The people that contact with me has different devices models and different versions of iOS 6.
I use AVAudioPlayer to play the files and I think that it work well.
Have you experienced the same problem?
Thank you
UPDATE
This is the Localizable.strings that I have
I load the file like this:
//
NSString *fileLang = NSLocalizedString(aItem.fileName, nil);
//more code ...
thePlayerURL = [[NSBundle mainBundle] URLForResource:fileLang withExtension:#"mp3"];
//more code ...
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL: aItem.urlAudio error:&error];
player.delegate = self;
[player prepareToPlay];
This is an example of the Localizable.strings with the file keys and values, by default the name of the key is the spanish version of the file:
//AUDIO NAMES
"1_au_es" = "1_au_en";
"2_au_es" = "2_au_en";
"3_au_es" = "3_au_en";
"4_au_es" = "4_au_en";
"5_au_es" = "5_au_en";
"6_au_es" = "6_au_en";
"7_au_es" = "7_au_en";
"8_au_es" = "8_au_en";
"9_au_es" = "9_au_en";
"10_au_es" = "10_au_en";
"11_au_es" = "11_au_en";
"12_au_es" = "12_au_en";
"13_au_es" = "13_au_en";
"14_au_es" = "14_au_en";
"15_au_es" = "15_au_en";
"16_au_es" = "16_au_en";
"17_au_es" = "17_au_en";
"18_au_es" = "18_au_en";
"19_au_es" = "19_au_en";
Have you ensured that their vibrate button isn't flipped on? I wrote a translate app that had the users simply mute/put the vibrate button flipped on. It seems simple, but I've gotten almost 15 emails for that alone, saying the app had no audio.
It seems simple, but that solution is the easiest and quickest fix. Vibrate mode, turns off all audio, even for the apps.
My translate App used AVAudioPlayer, and there was nothing programmatically wrong. Just simply user error.
Maybe the audio bitrate could be the problem? I really don't know...
The bell, than works well has 128kbps and the audio files have 96kbps and sometimes don't work. The strange thing is that the audio works very well for the 90% of the uses but sometimes fail. The bell instead work well the 100% times.
:/
Is very difficult to find the precise solution to this problem without checking your Xcode project configuration. However, by the information that you mentioned in the comments, I suspect that the problem must be related with the Localization strings. Check your localization configuration, check that you are using the localization strings files correctly, check that you wrote a valid filename for each supported localization.
Also, checking your code:
NSString *fileLang = NSLocalizedString(aItem.fileName, nil);
//more code ...
thePlayerURL = [[NSBundle mainBundle] URLForResource:fileLang withExtension:#"mp3"];
//more code ...
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL: aItem.urlAudio error:&error];
player.delegate = self;
[player prepareToPlay];
Why you are not using "thePlayerURL"?. Maybe that is the problem, since is the "Localized URL". I would expect:
NSString *fileLang = NSLocalizedString(aItem.fileName, nil);
//more code ...
thePlayerURL = [[NSBundle mainBundle] URLForResource:fileLang withExtension:#"mp3"];
//more code ...
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:thePlayerURL error:&error];
player.delegate = self;
[player prepareToPlay];
I recently submitted an application that was having the same problems, but it was denied due to the fact that I hadn't setup "Inter-App Audio" in Xcode and in the Certificates pane under the app info. That may help.
In case you are wondering, the application was in violation of Section 2.13 of the App Store Guidelines.
This has driven me nuts for a long time now. I am using Xcode 4.6 but this has been happening for several versions. When I turn on breakpoints and add the Exception Breakpoint, it always pauses on a line of code where I'm setting up an audio player. I set some up before and after the same way, but it only pauses on that one.
Here is the code I'm using:
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
self.playedSongs = [NSMutableSet setWithCapacity:9];
[self loadSettingsFromFile];
NSURL *sfxPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Snap.aiff" ofType:nil]];
self.snapSfx = [[[AVAudioPlayer alloc]initWithContentsOfURL:sfxPath error:nil]autorelease];
self.snapSfx.volume = 1.f;
NSURL *fireworksPath;
if ([OriginalIPadChecker isNotiPadOriginal]) {
fireworksPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"FireworksSFX.mp3" ofType:nil]];
}
else{
fireworksPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"NoFireworksSFX.mp3" ofType:nil]];
}
self.fireWorksSfx = [[[AVAudioPlayer alloc]initWithContentsOfURL:fireworksPath error:nil]autorelease];
self.fireWorksSfx.volume = 1.f;
NSURL *poofPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Remove Poof.mp3" ofType:nil]];
//The line below is the one that it pauses on
self.removePoof = [[[AVAudioPlayer alloc]initWithContentsOfURL:poofPath error:nil]autorelease];
self.removePoof.volume = 1.f;
NSURL *newHighScorePath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"New High Score.mp3" ofType:nil]];
self.theNewHighScore = [[[AVAudioPlayer alloc]initWithContentsOfURL:newHighScorePath error:nil]autorelease];
self.theNewHighScore.volume = 1.f;
NSURL *badgeInTrophyPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Badge In Trophy.aiff" ofType:nil]];
self.badgeInTrophy = [[[AVAudioPlayer alloc]initWithContentsOfURL:badgeInTrophyPath error:nil]autorelease];
self.badgeInTrophy.volume = 1.f;
NSURL *dingPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Ding.aif" ofType:nil]];
self.ding = [[[AVAudioPlayer alloc]initWithContentsOfURL:dingPath error:nil]autorelease];
self.ding.volume = 1.f;
The app doesn't crash and the sound plays fine, but the debugger always pauses on that one lineāeven if I move it somewhere else, it still pauses. I can continue the execution and it works just fine, but this really bugs me.
I don't get why it pauses. Any ideas?
As explained in the comment of Xcode stops on prepareToPlay, the reason for the breakpoint is that you were setting a generic breakpoint of type 'exception on All' which responds to a signal which is fired by the c++ library. It is better to use an "Objective-c" exception breakpoint, which will protect for such cases.
Try this and update the question on where it stops (if it stops):
AVAudioPlayer *foo;
NSError *error = nil;
assert(poofPath);
foo = [AVAudioPlayer alloc];
foo = [foo initWithContentsOfURL:poofPath error:&error];
assert(foo);
[self setRemovePoof:foo];
[foo release];
If the assert kicks in, that's probably an Apple issue. Unfortunately there are cases of Apple internal frameworks using try/catch, and they will trigger the breakpoint. Its not common but does happen.
If in the end that foo is not nil and the error is also nil, the best you can do is enter a bug report at bugreporter.apple.com (which would be great). Also, did you look at poofPath - is there any chance that the URL returns anything other than pristine audio?
My guess is that Apple tries to open and process the file, its gets an internal exception because there is something "odd" or abnormal about the file. Then the framework does additional work, and manages to read the file. So you get your sound but the exception too. Take some common type of mp3 and put that in your app bundle, and try to open it. See if it (and maybe a few other files) gives the same error. Or create a demo project with the sound and upload it (in the end you may need to submit the demo project to Apple in a bug report). These kinds of things should be bug reported.
EDIT: Unfortunately there are cases of Apple internal frameworks using try/catch, and they will trigger the breakpoint. Then, as mentioned earlier, some later code finally figures out how to decode the file and does.
The original poster has responded in a comment that this particular file was created with Audacity, and has heard that such files often have decode issues.
I am creating UIManagedDocument and I don't know why I get the error saying:
Thread 1: EXC_BAD_ACCES code=1 address=0xdeadbeef
The only thing in my code is the creation of this UIManagedDocument. This function is called in viewDidLoad:
- (void)setupDatabaseDocument
{
if(!self.databaseDocument){
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:#"Default Database"];
NSLog(#"self.databaseDocument will be initWithFileURL:%#",url);
NSLog(#"%#",[[[UIManagedDocument alloc] initWithFileURL:url] class]);
self.databaseDocument = [[UIManagedDocument alloc] initWithFileURL:url];
}
}
I tried to print through NSLog the class of [[UIManagedDocument alloc] initWithFileURL:url] to see if it is of object type UIManagedDocument but then the EXC_BAD_ACCESS appeared again in the NSLog line of code.
I don't know if the following details are relevant to the problem: I use Xcode 4.3.3 with iOS 5.1 Simulator. I tried running this with iOS 5.0 Simulator but the same error appeared. My Mac OS X version is 10.7.4.
Why do you think am i getting this error?
if (!streamer) {
NSURL *url =[NSURL URLWithString:#"http://y1.eoews.com/assets/ringtones/2012/5/18/34049/oiuxsvnbtxks7a0tg6xpdo66exdhi8h0bplp7twp.mp3"];
AudioStreamer *tempStreamer = [[AudioStreamer alloc] initWithURL:url];
self.streamer = tempStreamer;
[tempStreamer release];
}
[streamer start];
When it begin to play, it crash in simulator and xcode shows the erro is :libc++abi.dylib`__cxa_throw, but it runs well in device.in another demo, it runs well both in simulator and device.
I can not find the reason.
If you have enabled beakpoint for All exceptions, please disable it from Breakpoint Navigator. This should solve your problem.