xcode 5 no sound from mp3 on iOS 6 or earlier - ios

The app plays some mp3 files and is working well on iOS 7, but on iOS 6 or earlier, the mp3 files are not played or at least I can hear nothing.
This is the code I use for playing mp3:
fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/puerta.m4a", [[NSBundle mainBundle] resourcePath]]];
//Initialize the AVAudioPlayer.
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
// Preloads the buffer and prepares the audio for playing.
[self.audioPlayer prepareToPlay];
self.audioPlayer.currentTime = 0;
[self.audioPlayer play];
Does anyone had a similar issue and how fixed it - Many thanks for help.

Related

AVAudioPlayer - Why is there a gap between loops (uncompressed audio)

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
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];
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

Play iOS built-in sounds with AVAudioPlayer

Is is possible to play built-in sounds with AVAudioPlayer, to get around the limitations of AudioServicesPlaySystemSound?
For example:
AudioServicesPlaySystemSound(1360);
vs.
AVAudioPlayer
NSURL* url = [[NSBundle mainBundle] URLForResource:#"???" withExtension:#"??"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[player play];
What would the path or code be (if possible)?

AVAudioPlayer Sound Different between identical devices with identical settings

I play a sound effect using:
-(void)playCorrectSound
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"Yes" ofType:#"mp3"];
NSURL *soundURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
if(! self.myAudioPlayer || ![soundURL isEqual:self.myAudioPlayer.url]){
self.myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
self.myAudioPlayer.delegate = self;
}
[self.myAudioPlayer setVolume:1.0];
[self.myAudioPlayer prepareToPlay];
[self.myAudioPlayer play];
}
I've added this code to three devices, all iPhone 5, all iOS 7.0.6 Two of them play the sound at significantly lower volume than another phone. All System preferences appear the same across all three devices. Would anyone know why one would be so much louder (and how I want it)?

Play multiple audio at one same time

My client wants to create an app in which user can play 4 audio at once and then start start any audio and then record them as one file.
I have not worked on audio/video apps so i want to know that is that possible in ios sdk?
How many audio file can be played at same time?
You can play many musics at the same time using AVAudioSession.
UInt32 allowMixing = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
You can play multiple audio file with this code
NSString *songA = [[NSBundle mainBundle] pathForResource:#"songA" ofType:#"mp3"];
NSError *soundError = nil;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:songA] error:&soundError];
if(self.player == nil)
NSLog(#"%#",soundError);
else
{
[self.player setDelegate:self];
[self.player setVolume:0.75];
[self.player play];
}
NSString *songB = [[NSBundle mainBundle] pathForResource:#"songB" ofType:#"mp3"];
soundError = nil;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:songB] error:&soundError];
if(self.player == nil)
NSLog(#"%#",soundError);
else
{
[self.player setDelegate:self];
[self.player setVolume:0.25];
[self.player play];
}
To marge more than one audio file you can use ans from this question Combining two .caf files on iPhone

MPMoviePlayerController unmutes hardware mute in AVAudioPlayer

I've set my phone to muted state by switching vibrate/sound hardware button. In whole application some background music is playing unless the device is in muted state. So in this case, my music is playing but muted. Now in some point I want to present video (which is without sound but this shouldn't matter), however the video in MPMoviePlayerController turns music from AVAudioPlayer on even though the device is is 'muted' state. The AVAudioPlayer continues to play loudly even when i quit MPMoviePlayerController.
Some code samples, but i doubt it will help:
// movie without sound
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];
NSURL *movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"]];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[_scrollView addSubview:_moviePlayerController.view];
[_moviePlayerController prepareToPlay];
[_moviePlayerController play];
// music
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[_audioPlayer prepareToPlay];
[_audioPlayer play];
To fix this, I had to rewrite the code but instead of using MPMoviePlayerController I've used AVPlayer. Everything works like a charm now.

Resources