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
Related
I'm using a MPMediaPickerControllerto enable the user to pick songs from the device's iPod library. Then I put this songs into an array (in this case playerQueue) and use an AVPlayer instance to play one song after the other:
- (void)setQueueWithItemCollection:(MPMediaItemCollection *)theCollection {
for (MPMediaItem *theMediaItem in theCollection.items) {
NSURL *mediaURL = [theMediaItem valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *thePlayerItem = [AVPlayerItem playerItemWithURL:mediaURL];
// Don't add protected tracks to queue as they cannot be played
if (!thePlayerItem.asset.hasProtectedContent && thePlayerItem.asset.isPlayable) [self.playerQueue addObject:thePlayerItem];
// Further implementation
}
}
Now I get the song title using this code snippet (with AVPlayer *musicPlayer):
AVPlayerItem *currentItem = self.musicPlayer.currentItem;
AVAsset *asset = currentItem.asset;
// Further implementation
NSLog(#"DEBUG: Meta data: %#", asset.commonMetadata);
NSArray *titles = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
Most times this works without any problem. But there are are also songs for which asset.commonMetadata returns an empty array. However the Music app on my iPhone is able to display the song title (and album artwork etc.) just like iTunes (on the Mac).
The song file is an Apple MPEG 4 Audio file purchased from the iTunes Store.
Why is asset.commonMetadata returning an empty array even though there are meta data available?
I was having this same problem with downloaded m4b audio files. Turns out that AVURLAsset requires the URL string to end in '.m4b' (other audio extensions would work, I suspect). You can't use the URL as is if it is something like http://source.com/download.php?id=12345. Otherwise, the asset.commonMetaData just returns an empty array. I don't know if this is a problem with iTunes assetURLs, but it would be easy to check.
The only solution that worked for me:
Use AudioToolbox.framework to retrieve metadata from such files, i.e. use AudioFileGetProperty function.
It seems like a real bug in AVFoundation…
I'm developing app for IPhones where users clicks button, gets the list of all videos from his IPhone and uploads chosen video to server.
I know how to upload video to server, but I don't know how to implement video searching.
How can I get pathes to all videos (in users IPhone) in Array?
(Currently my IPhone is unavailable for use, so I'd like to know also how to test video search in IPhone Simulator?)
Kind Regards
You need to use the UIImagePickerController component, configuring it to show only videos when browsing the library.
You can do that by setting the mediaTypes property of the picker in this way:
myImagePickerController.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
Then if you want to test it in the simulator, you need to save some videos on it and you can use the UISaveVideoAtPathToSavedPhotosAlbum function to achieve that. Check out this great answer for more detailed instructions.
This link shows how to access only videos from the photoroll since all videos of the device should be stored there, you should be able to access them from there: Picking video from PhotoLibrary with UIImagePickerController in OS 3.1
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.
Im using MPMediaQuery to search the library on a user's iPhone/Pad. Im able to return audio tracks but im unable to return any of the videos which are on the device. Apparently its not possible according to this article but i fail to understand why this would be. If that is true, is there another way to retrive this information?
This is how im retrieving tracks
MPMediaQuery *queryTracksByArtist = [MPMediaQuery artistsQuery];
MPMediaPropertyPredicate *pred = [MPMediaPropertyPredicate predicateWithValue:#"The Album Title" forProperty:MPMediaItemPropertyAlbumArtist comparisonType:MPMediaPredicateComparisonContains];
[queryTracksByArtist addFilterPredicate:pred];
NSArray *itemsFromGenericQuery = [queryTracksByArtist items];
No, As of now, you cannot access video with ipod library access. check this link.
I created my own music player that runs on iPhone using the class MPMusicPlayerController.
I'm using the class MPMediaPickerController to select the songs and add to my player.
I've around 900 songs in my iPhone. When I'm adding songs by selecting "Add All Songs" from MpMediaPickerController, the app is crashing.
Can some one tell me whether is there any solution to stop this crash?
Or is there any limit on number of songs selection that I've to impose so that app won't crash?
No, there is no limit on selection of songs.