How to create a local songs application in iPhone ? - iphone

I have created a music application in which I have 5 songs added to my resources folder. When I click on a button, I want all these songs to be displayed in the tableview cell of my table-view controller.
Please anybody help me to solve this problem.Actually I know to retreive songs from the documents folder of my application .But the problem is when I put songs in the document folder and if I delete my simulator applications the music files inside the documents folder becomes null and when I run my application it shows no songs.
Please help me to solve this problem.

Well when you delete your app the document directory is also delete, as the document directory is in the app sandbox and can only be accessed by your app.
So you will need to ask the NSBundle for the songs:
NSString *songFilePath = [[NSBundle mainBundle] pathForResource:#"Song1" ofType:#"mp3"];
Just repeat this for every song then put them in a Array so you can easily display then in the TableView.

Related

Swift App: User selects playlist and then fills in buttons with each song?

I'm trying to create a mediaplayer app. I was wondering if there is a way, and how would that look, to program the app so that a user can select a playlist from their own library and those songs from the playlist would be added to various buttons. For example, a user selects a playlist that has 10 songs. Those 10 songs would then would be assigned to 10 separate buttons, not a tableview, so that a user can tap the button to play a selected song from that playlist.
If you want to use Apple Music library, than it will not work because Apple does not allow any manipulations with data (licensed songs) in their apps. But if you create a library of songs downloaded from somewhere inside of your app, then you can easily do it, but you should expand on that in a different post.

ios: cache images in the application folder

I am working on an Iphone application.
The idea of the application is to allow the user to download a picture and to save it on his phone. and he can later open it. (Normal caching system)
What I am doing now is I get the UIIamge from the server and then I save it on the phone using:
UIImageWriteToSavedPhotosAlbum
And then I use the imagePickerController to allow the user to load the image.
My question is:
Is there a way I can save the image in the application folder? The idea is that I don't want to allow the user to delete the image from outside the application(I have a "clear images" button). Is there a place I can cache the images other than the Photo library? maybe in the application bundle or folder?
Thank you
Use either of the following methods to save the UIImage into your app's document directory
[UIImageJPEGRepresentation(image, JPEG_COMPRESSION_QUALITY)
writeToFile:photoPath atomically:YES];
or
[UIImagePNGRepresentation(image) writeToFile:photoPath atomically:YES];

How to get the number of music files our device having

iam developing one application.In that i need to get the how many music files are there in my device.Iam using the MPMediaPickerController for selecting the music files.But i want to get the number of files that device having with open and select the files from the picker.So please tell me how to get that number.
To get all the songs use the following
MPMediaQuery *allSongsQuery= [MPMediaQuery songsQuery];
NSArray *songs = [allSongsQuery collections];
If you want open and select, you will have to do some more work

Play audio from tableview and advance to next file in list

I present the user with a table view of all the audio files listed in their documents directory of the app, alphabetically. I would like to allow advancing to the next track using headphones or the iPod audio controls built into iOS, but am not sure how to advance to whatever the next track is in the documents. My code to play it is to simply get the path to documents, and append it with the name of the row they click on in the table view. Is there a simple way to get the next file name from the path?
You should probably get the contents of the folder in an array and then display it in a table after sorting. By this, every row points to a file in the array, which can be retrieved and played. To get the contents of a folder use the following line:
- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error;

iPhone application cannot load images from an album

I have developed a small iPhone application in which a user can choose images from an image picker and that image will appear in a View. When the user first selects an image I have saved the image name to a database and I save that image to a resource folder with that name. When the main view appears I search for images from the resource folder and display that image in the main view.
When I run this application in the iPhone Simulator it successfully runs, but when I actually tried it for testing purposes on my iPhone I am not able to display images in the main view. Anyone have an idea what's wrong with that?
Hi shivang,
I think you are saving the image to NSDocumentDirectory on a first click and trying to reload that.
while retriving the files from the NSDocumentDirectory you better
first check it for the file type like jpg,png,mp3 then give the
exact name to retrive that.
NSDocumentDirectory creates unique memory for every app and its
limited,check for the size of the images u r saving.
better try this code
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath:myfilepath error:nil])
{
if ( [fileName rangeOfString:#".jpg"].location != NSNotFound )
{
// Here fileName is used as a temporary variable to retrive image name
// myfilepath is the path where u stored the images
}
}