Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I want to be able to use the MPMediaPickerController on local files that were downloaded in the Documents directory.
However, there is no option to set the source of the files that the controller looks in, which defaults of course to the iPod music library.
Are there any methods to load local files, or any alternate libraries available to provide the media picking functionality? Or will I have to reinvent the wheel here :(
You might want to take a look at AVAudioPlayer instead, seeing as MPMediaPickerController is a class designed to play music stored only in the iTunes media folder. It's also very easy to play media with from the doc directory:
NSString *soundFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:#"mySong.m4a"];
NSURL *fileURL = [NSURL URLWithString:soundFilePath];
NSError *error;
AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if(!error){
audioPlayer.delegate = self;
[audioPlayer play];
}else{
NSLog(#"Error loading clip: %#", [error localizedDescription]);
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm building a data which can store images into iOS document directory. I'm able to store the data in the document directory but how can I access it.And what is purpose of directory in iOS apps when there is persistent data store technologies like core data.Whether I can use directory to get persistent storage or I should go for core data.
I think, document directory is better solution in your case. Core data is useful for maintaining records corresponding to multiple fields.
Just use NSFileManager, something like this:
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
It will give you an array with all the file paths for all files in the given path.
This is how you load the images from the array of URLs.
NSArray *paths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
for (NSURL *url in paths)
{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
}
Have you tried using UIDocumentPickerViewController?
This is Apple documentation: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller
Here is a tutorial:
https://medium.com/flawless-app-stories/a-swifty-way-to-pick-documents-59cad1988a8a
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I need to download a particular webpage on my iphone.
It redirects me if i use a desktop.
Any tools out there that could help me to do this?
I have tried sitesucker but it didnt work.
Thanks!
If it redirects you when you use a desktop to access it, you can right click the link and download page as source. But since you want to do it on the iPhone, you can do the following:
// Download webpage
NSURL *url = [NSURL URLWithString:#"https://yourURL.here"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
And you can access the data through your simulator folder or you directly get the NSString.
NSURL *url = [NSURL URLWithString:#"https://yourURL.here"];
NSString *source = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
someone know idea regarding to fetching sound data from webservice? I used simple play, pause, stop sound to access application resources folder. Now i want to update this. plz, having some idea. thanks in advance.
This is for downloading audio file from server
NSData *soundData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"SoundURL"]];
after downloading
AVAudioPlayer has a method for playing sound from NSData object .
You can use
- (id)initWithData:(NSData *)data error:(NSError **)outError method of AVAudioPlayer
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have an music application that plays songs from urls using AVPlayer. According to new requirement user should be able to listen their local songs (contines in phone memory) also through this music app. I want to know few things about this.
1) How to access local memory within my application.
2) Can I use already exists AVPlayer to play local songs too.
Any tutorial or examples uch appreciated.
Thanks
1) It depends on what you mean by 'local memory'. You app's local folder, or the device's iPodLibrary?
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory()
stringByAppendingPathComponent:#"Documents"];
NSLog(#"Content of local documents directory: %#",
[fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil]);
This will print out all the files that's currently in your app's document-folder. You can store files here too. This is only for your app, not shared by any other app on your device. I do not think you're able to find the .m4a-audio files from your iPod from your application, I'm guessing Apple has hidden them so developers can't mess with them, or start pirating etc.
2) As it turns out, it looks like you can! Take a look at this answer.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Currently I'm developing an app which will download some videos from a "computer device".
These videos will be played in the app -> for proper sync. another file is needed (each video has its coresponding file).
I have done some research on where should I store this... but there is no certain anwser (at least for me at this point).
Read this Guide to some point
I assumed the "/cache" folder is suitable?
Which folder should I use in this case? I want the video to be playable in an "offline" situtaion. These videos can "weight" a little thus I don't want any iCloud sync for them.
While items in the caches directory do not get backed up to iCloud they can be purged by the system if under pressure to reclaim disk space. You could potentially store it in the users documents directory if it's "user generated" data.
An appropriate place to store downloaded content that your app needs offline would be the Application Support directory (Library/Application Support).
NSArray *appSupportURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
NSURL *applicationSupportDirectory = appSupportURLs[0];
You should also set attributes on files located elsewhere (Application Support, Documents, etc.) if you do not want them to be backed up. You can find more on it here: http://developer.apple.com/library/ios/#qa/qa1719/_index.html
Use NSCachesDirectory. It won't be backed up in iTunes or iCloud.
NSArray *cachedirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachedir = cachedirs[0];