AVAudioPlayer error with m4a but not mp3 - iphone

I'm pretty confused by this one and can't think of anything obvious that I am doing wrong.
I can't get iOS to pull an m4a out of my app bundle
eg
NSURL *clickurl = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/fishy2.m4a", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:clickurl
error:&error];
audioPlayer.delegate = self;
if (error)
NSLog(#"Error: %#",
[error localizedDescription]);
else
[audioPlayer play];
I get an error -43
However, if I instead use an identical mp3 instead
NSURL *clickurl = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/fishy.mp3", [[NSBundle mainBundle] resourcePath]]];
everything is happy
I've tried this many many times across different projects and can't see where I'm going wrong. I've been using NSFileManager to check if it is there and it says no to the m4a, but yes to the mp3. Tried this with all manner of different methods of importing different audio files in different formats and I can't seem to get it to find the m4a (and it really really has to be m4a). mp3, wav, caf etc... all work. Interestingly, the m4as that I run from the user documents directory work just fine
All I want is to be able to copy the file!
Any ideas at all?

Work around = right click and "add files to " instead of dragging

Related

No sound in iPhone simulator for XCode 4.6.3

I have tried several options (many of them referenced from this post on SO and elsewhere) to get music to play on the iPhone simulator, but so far none of it has worked. I have tried -
Unchecking, and then checking the box that says "Player user interface sound effects" in the Preferences > Sound option
Going to Audio Midi Set Up, and changing the sample rate to 44100
Ensuring that the output/input is both using the internal speakers
Make sure that I imported <AVFoundation/AVFoundation.h> and added the AVFoundation.framework to my linked frameworks.
Resetting iOS simulator using Reset Settings/Contents
Restarting XCode, as well as as the computer
I have the following code in viewDidLoad that is play the file gundam.mp3
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"gundam" ofType:#"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1;
player.volume = 0.9;
NSLog(#"The sound URL is %#", soundFileURL);
[player play];
The NSLog seems to be able to capture the file correctly: The sound URL is file://localhost/Users/zallanx/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/[...]/Missile%20Defender.app/gundam.mp3
I am unsure what I am doing incorrectly based on all the options I have tried, and would appreciate your help. Thanks!

MPMoviePlayerController can't read file in document path

I recorded a video and copied it to the path
NSURL *videoPath =[NSURL URLWithString:[NSString stringWithFormat:#"%#%#",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUsersDomainMask,YES) objectAtIndex:0],#"/output.mov"]];
Then use MPMoviePlayer to play it:
MPMoviePlayerController *player = [[MPMovieController alloc] initWithContentURL:videoPath];
This does not work. The video can't get loaded. The file path is
"/var/mobile/Applications/12341235-12354125-123412-41/Documents/output.mov"
Does anyone know why?
For some weird reason, MPMoviePlayerController doesn't seem to like certain NSURLs even though they are deemed as valid objects.
The "secret" is to get the file path as NSString and then use [NSURL fileURLWithPath:URLStringPath] to create the URLs your are using to create the MPMoviePlayerController instance.
i think you forgot to set / for your file path use like this
NSURL *videoPath =[NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/%#",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUsersDomainMask,YES) objectAtIndex:0],#"output.mov"]];

Extended Audio File Services: ExtAudioFileRead

How to use Extended Audio File Services: ExtAudioFileRead to Performs a synchronous, sequential read operation on an audio file.
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"theme"
ofType:#"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];
[fileURL release];
How i can Performs a synchronous, sequential read operation on theme audio file. Currently have AVFoundation.Framework and should i add CoreAudio.Framework too.
To use Extended Audio File services, you'll need to link to AudioToolbox.framework
Opening and reading a file using this API is fairly involved. There's some good information here, and the Documentation.
For my part, I've found the headers in AudioToolbox.framework to have the best documentation. See ExtAudioFile.h

AVAudioPlayer. Optional redirect of audio files. In _audio i am getting null

I have debug this code in url I am getting the "fileName" string, which i want. But in _audio i am getting null.
I am using an AVAudioPlayer to play and stream audio files. I am playing audio files from resources and document directory, but if they are absent in document directory then I want to play that specific audio from it's url. By streaming and buffering it. Here is my code:
NSString *fileName = #"http://ilm.coeus-solutions.de/frontend/images/audios/mp3test.mp3";
fileName = [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:fileName];
AVAudioPlayer *_audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
You can try following code,
NSData *filelocation=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:#"http://ilm.coeus-solutions.de/frontend/images/audios/mp3test.mp3"]];
MyAudioPlayer = [[AVAudioPlayer alloc]initWithData:filelocation error:nil];
hope this will solve your problem
Slam dear! Please read again my question I have just asked about audio streaming rather than downloading it and then playing it.
This below link helped me. By the way thanks all who try to help me.
http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html
Thanks!

Couldn't put a song into an app

Have already tried that out and failed
I put a .wav file into my app and it was fine. So I tried to put a .wav song file into the app. When runs, there's no sound coming out. ( the song is converted from .mp3 using iTunes)
Any ideas how can I fix this? Thanks in advance
one possible reason the sound file is too large. You have different kinds of audio player in iOS some of them can only play files that are really short (something like 1-3 sec). To fix that you have to choose another player like CoreAudio.
The second possible failure is the simulator. The simulator is not always doing the same, the device do. Try running on real device and check if it's working.
// EDIT: sample code:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"mySound" ofType:#"mp3"];
NSURL *soundFileURL = [NSURL URLForString:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundFileURL];
[player play];
[player pause];