1

I need to play a video along with a small 2 sec audio play. Everything works fine in iPhone simulator but not in the Device. I am storing my audio file in the project bundle and playing the audio from there.

NSString *gotItsoundFilePath = [[NSBundle mainBundle] pathForResource:@"gotit" ofType:@"mp3"];
    NSData *gotItsampleData = [[NSData alloc] initWithContentsOfFile:gotItsoundFilePath];
    NSError *gotItaudioError = nil;
    gotItAudioPlayer = [[AVAudioPlayer alloc] initWithData:gotItsampleData error:&gotItaudioError];
    gotItAudioPlayer.numberOfLoops = 0;

This code works fine in iPhone Simulator when i use [gotItAudioPlayer play]; but the same build is not working in the device. Am i doing wrong somewhere? Can someone please help on this?

Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75

1 Answers1

5
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

Put this code. before you make player object.

user1239633
  • 88
  • 1
  • 4