Reputation: 33
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"caf"];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer setVolume: 0.1];
[audioPlayer play];
This is the basic code I've got, let me know if you need to know more.
tried both compressed and uncompressed formats both have a gap of about ~1 second when running on iPhone simulator (don't have dev license to run on device to test).
Am i missing something, I've been searching posts but i can only see issues with compressed audio (which makes sense).
Xcode: Version 6.2 (6C131e)
OS: OS X Yosemite Version 10.10.2 (14C1510)
Hardware: Macbook Air 13" (Early 2014) - 4GB
Upvotes: 3
Views: 708
Reputation: 1697
I had the same issue and I solve it using AVQueuePlayer, Create one AVQueuePlayer player and try to buffer (enqueue) two or three AVPlayerItem with mp3 media files in advance in a lazy mode via AVPlayerActionAtItemEnd
Upvotes: 0
Reputation: 61
have you try a "prepareToPlay" before playing like this :
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"caf"];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer setVolume: 0.1];
[audioPlayer prepareToPlay];
[audioPlayer play];
Upvotes: 1