Programmatically Accessing iPod Library - iphone

How could I select and play a song in an iPhone user's library using objective-c? Thank you so much! I couldn't find how using Apple's documentation or Google.

The relevant class for finding available songs is MPMediaQuery. There are a bunch of filters you can use to get a subset of the iTunes library returned. You'll end up with an NSArray of MPMediaItem. You can use the valueForProperty: method with the MPMediaItemPropertyAssetURL property to get a URL that references the item.
They won't generally be normal file URLs, but they are URLs that the AV Foundation is able to use so an instance of AVAudioPlayer should be able to play a song.

Related

Deleting photos from phone using UIImagePickerController

The documentation indicates : pick a photo from library or camera roll and delete with user permission.
Is that possible using UIImagePickerController? Or does a user have to explicitly delete the selected photo?
This isn't possible regardless of what you use to try to accomplish it. The UIImagePickerController is only for choosing photos and does not modify them in any way. A more promising way, would be with the Assets Library but, even with this framework, you are unable to delete a users photos. That being said, if you want to use this functionality in your app, it will have to be for jailbroken devices only.
In short, the user has to navigate to the photos app and delete the images themselves.
Thanks to the iOS 8 Photos Framework, you can now delete images from the user library! I recommend you check out Apple's example app using the Photos Framework for a more detailed example of how to use it, but the relevant bit is:
//under SamplePhotosApp/AAPLAssetViewController.m
// Delete asset from library
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[PHAssetChangeRequest deleteAssets:#[self.asset]];
} completionHandler:completionHandler];
where self.asset is a PHAsset object (which can be acquired in several ways) referring to the photo you wish to delete. Oh, and don't forget to import the Photos framework!
Hope this helps!

Accessing media library in iOS

I want to access songs from media library and then want to cut a part of that song.
I have written function to cut a song from bundle and it is working fine.
Now I want to allow user to select song from library, how can I do that?
Just like how you access all other media in ios- using AssetsLibrary, more about this here:
http://developer.apple.com/library/ios/#documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/MediaLayer/MediaLayer.html
Be aware that all the media is read only and you can manipulate only a copy of the songs and not the original.

Not able to access iPod library path

I am using Media Player Framework and its MPMusicPlayer controller for integration with iPhone's default player. I got the asset URL as :-
ipod-library://item/item.mp3?id=4157200259458444598
Now I need to access this URL for copying this song to my application's 'song.mp3' file. Can anyone please help me to access the iPod URL so that I can use it in my iPhone app as the way I want.
Any quick help is really appreciated.
Apple do not allow you to copy the contents of the iPod library out to your user area. This is to prevent copyright infringement. If you want to just play the song then you'll need to post a more detailed question.

Access iPhone User Songs and Videos?

I was wondering if I can access user's songs and videos in iPhone, part of that access if I can save them or modify them? hopefully not a Jailbroken iPhones
I am greatly appreciated.
Yes, you can. I can't speak for video, because I've only done it for audio, but you can definitely get audio data. These links should get you started. Note: I am as yet unsure if this works with tracks that use any kind of iTunes-related DRM.
First of all, this blog post talks you through the method of accessing the data. Note the reliance on iOS 4.1 or above.
This SO question/answer explains how to get at the raw pcm data, should you want to do more than just save it out.
You can allow the user to pick songs using the MPMediaPickerController class. I think you can save the selected item to your app's sandbox directory.
You can read up on this a bit more with this SO question.

How to read all images from iphone photo library into application and how i would i get path of photo library?

How to read all images from iphone photo library into application and how i would i get path of photo library??
To read all images from iPhone photo library, use the "assets library framework".
You can check out Apple's documentation here:
http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/AssetsLibraryFramework/_index.html
There is a ALAssetsFilter called "allPhotos", you can use the filter with the setAssetsFilter: and the enumerateAssetsUsingBlock: methods in ALAssetsGroup to achieve this.
Here is some sample code implementing this:
http://www.icodeblog.com/2010/07/08/asset-libraries-and-blocks-in-ios-4/