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?
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
Put this code. before you make player object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.