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
Related
how to import *.pdf all pdf from my iphone to my app like this add music file. http://developer.apple.com/library/ios/#samplecode/AddMusic/Introduction/Intro.html .Thanks in advance .New to iphone dev.Really appreciate any help.
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *mgr = [[NSFileManager alloc] init];
NSArray *allFiles = [mgr contentsOfDirectoryAtPath:bundlePath error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:#"pdf"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
// fullFilePath now contains the path to your pdf file
// DoSomethingWithFile(fullFilePath);
NSLog(#"file: %#",fullFilePath);
}
}
NSURL *url = [[NSBundle mainBundle] URLForResource:#"" withExtension: #"pdf"];
NSLog(#"File: %#",url);
You can just email the pdf file as attachment and the iphone can read it on its own. That feature already exists within the iOS of the iPhone or you could upload them somewhere (on your server) and send the links.
You can't just browse all the files on the phone from within your App.
As I said to you in the comment on your other questions (which, by the way is almost exactly the same as this one, but in the other question you ask about csv files rather than pdf), you need to read up about the App Sandbox.
In a nutshell, Apps can only see their own files and those that are written by the App. All apps have their own storage space and they can only see in that area.
Having said that, it is possible to pass some files around between apps, but they have to be written to support that. There is no such concept as a global file system on iOS devices.
READ THIS
I have an app that downloads MP3 files from our web server and momentarily stores them in an NSData object. This object is then written to a .mp3 file stored to the /Library/Cache folder in the app's sandbox.
When it is time to play the file, I load it into an AVPlayerItem like so:
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.mp3", trackID]];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
self.trackPlayerItem = [[AVPlayerItem alloc] initWithURL:fileURL];
I think proceed to load this item into an AVPlayer and play it.
So my main question is: How do I encrypt these mp3 files while they're stored on the disk to ensure they can't just be plucked from the file system by anyone with a Jailbroken device?
I've already looked on Stack Overflow but couldn't find anything that helped.
Hope someone can help me out. Thanks
Check out this thread on adding RSA encryption/decryption to NSData.
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"]];
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
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!