Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

ios - Is it possible to get video-related meta info for an MPMediaItem?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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",
... 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...