问题
I'm doing some work with MPMediaItems, and specifically I'm trying to get a list of the videos on a user's device. Now, videos from iTunes will be locked so they can't be played from a third-party app, but user-added videos like home movies are playable, and even those from iTunes can have their meta information queried and displayed.
But here's where I'm getting tripped up: I can't seem to find any video-specific meta info for these files?
The MPMediaItem class reference has a long list of properties that you can access, but they're mostly audio-specific. Things like MPMediaItemPropertyAlbumTitle
or MPMediaItemPropertyComposer
. There's even a section for Podcast-specific properties, but I can't seem to find anything like "Season Number" or "Episode Number" or "Show Title". This information is obviously stored by iTunes, and it's displayed by the in-house Videos app, but I can't find any way to get it myself.
These are the only fields I can find in the class reference:
NSString *const MPMediaItemPropertyPersistentID ; // filterable
NSString *const MPMediaItemPropertyAlbumPersistentID ; // filterable
NSString *const MPMediaItemPropertyArtistPersistentID ; // filterable
NSString *const MPMediaItemPropertyAlbumArtistPersistentID ; // filterable
NSString *const MPMediaItemPropertyGenrePersistentID ; // filterable
NSString *const MPMediaItemPropertyComposerPersistentID ; // filterable
NSString *const MPMediaItemPropertyPodcastPersistentID ; // filterable
NSString *const MPMediaItemPropertyMediaType ; // filterable
NSString *const MPMediaItemPropertyTitle ; // filterable
NSString *const MPMediaItemPropertyAlbumTitle ; // filterable
NSString *const MPMediaItemPropertyArtist ; // filterable
NSString *const MPMediaItemPropertyAlbumArtist ; // filterable
NSString *const MPMediaItemPropertyGenre ; // filterable
NSString *const MPMediaItemPropertyComposer ; // filterable
NSString *const MPMediaItemPropertyPlaybackDuration;
NSString *const MPMediaItemPropertyAlbumTrackNumber;
NSString *const MPMediaItemPropertyAlbumTrackCount;
NSString *const MPMediaItemPropertyDiscNumber;
NSString *const MPMediaItemPropertyDiscCount;
NSString *const MPMediaItemPropertyArtwork;
NSString *const MPMediaItemPropertyLyrics;
NSString *const MPMediaItemPropertyIsCompilation ; // filterable
NSString *const MPMediaItemPropertyReleaseDate;
NSString *const MPMediaItemPropertyBeatsPerMinute;
NSString *const MPMediaItemPropertyComments;
NSString *const MPMediaItemPropertyAssetURL;
NSString *const MPMediaItemPropertyIsCloudItem ; // filterable
I'm fairly confident that this information isn't available through the MPMediaItemProperties values, but can it be accessed in any other way? Is there even a round-about method for accessing this information, something like this answer which I don't completely understand but which seems promising, or is it completely impossible for a developer to see what show/season a video is from?
EDIT: This became especially important recently, because the most recent version of iTunes now no longer even presents those audio-specific fields (like "Album" or "Artist") when editing video files. Going to "Get Info" on a video file in iTunes now only shows the video-specific fields, meaning that videos input after this update now seem to be completely un-sortable in a third-party app.
...unless someone has an idea?
EDIT 2: In my research I've come across the AVMetadataItem
class, which I'd never heard of before, and specifically the AVMetadataiTunesMetadataKey
options (class reference). They don't seem to include Show, Season, or Episode info, but they do have some video-specific fields like AVMetadataiTunesMetadataKeyDirector
. Is there some other use of this class, or some other video-related class like AVAsset, that might have a roundabout access to the info I'm looking for?
EDIT 3: Got my hopes up when I found the iTunes Library Framework, which includes a ITLibMediaItemVideoInfo
class that is EXACTLY what I'm looking for. However, it seems to be Mac-only, and I need it on iOS... Any chance someone has a work-around to access this info on iOS?
回答1:
This may help you with exactly what are you looking for: https://code.google.com/p/subler/source/browse/trunk/mp4v2+wrapper/MP42AVFImporter.m
Here is a highlight of the relevant section you may be interested in related to AVMetadataKeySpaceiTunes
:
...
@"Description", @"desc",
@"Long Description", @"ldes",
@"Media Kind", @"stik",
@"TV Show", @"tvsh",
@"TV Episode #", @"tves",
@"TV Network", @"tvnn",
@"TV Episode ID", @"tven",
@"TV Season", @"tvsn",
@"HD Video", @"hdvd",
@"Gapless", @"pgap",
@"Sort Name", @"sonm",
@"Sort Artist", @"soar",
@"Sort Album Artist", @"soaa",
@"Sort Album", @"soal",
@"Sort Composer", @"soco",
@"Sort TV Show", @"sosn",
@"Category", @"catg",
@"iTunes U", @"itnu",
@"Purchase Date", @"purd",
...
来源:https://stackoverflow.com/questions/29283960/is-it-possible-to-get-video-related-meta-info-for-an-mpmediaitem