0

I have an Ipad application in which i am playing a bit of sound after my operation success .it was working fine earlier.i am doing like this `

NSError *error;
NSString *bell = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"aif"];
AVAudioPlayer *av = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:bell] error:&error];
if(error) {
    NSLog(@"%@",&error);
}
[av play];

but now the sound is not playing in ipad device.but in simulator it was working fine?can anybody help me?

Abizern
  • 146,289
  • 39
  • 203
  • 257
hacker
  • 8,919
  • 12
  • 62
  • 108
  • check out this url http://wfmu.org/ssaudionet.shtml and second is https://developer.apple.com/library/ios/#documentation/networkinginternet/conceptual/streamingmediaguide/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html just try... – Paras Joshi Sep 17 '12 at 08:35
  • Are you getting an error? Are you sure you are setting the name of the file correctly? The simulator is not case sensitive, the device is. Also, you should check that the result `av` is `nil` before checking the error parameter. – Abizern Sep 17 '12 at 08:41

1 Answers1

1

Check if file exists:

 NSError *error;
 NSString *bell = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"aif"];
 if([[NSFileManager defaultManager] fileExistsAtPath:bell]){
  AVAudioPlayer *av = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:bell] error:&error];
  if(error) {
   NSLog(@"%@",&error);
  }
  [av play];
 }
 else 
 {
   NSLog(@"File doesnot exist");
 }

Note :Check phone is not set to silent mode

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • i was not in silent mode.but i muted the phone then unmuted then its started playing.i think its a hrdwr issue – hacker Sep 17 '12 at 09:17