获取 iPod 库中项目的专辑年份?
尝试以下代码:
// Per albums
MPMediaQuery *albumsQuery = [MPMediaQuery albumsQuery];
NSArray *collections = [albumsQuery collections];
for (MPMediaItemCollection *collection in collections)
{
NSDate *collectionReleaseDate = [collection valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"collection release date: %@", collectionReleaseDate);
MPMediaItem *representativeItem = [collection representativeItem];
NSDate *representativeItemReleaseDate = [representativeItem valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"representativeItem release date: %@", representativeItemReleaseDate);
}
// Just per item
MPMediaQuery *query = [[MPMediaQuery alloc] init];
NSArray *items = [query items];
for (MPMediaItem *item in items)
{
NSDate *date = [item valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"release date: %@", date);
}
在所有情况下,我的 NSDates 都为零...... 但在 iPod 库中我可以看到日期,因此信息必须可用。 正确的获取方式是什么?
Trying the following code:
// Per albums
MPMediaQuery *albumsQuery = [MPMediaQuery albumsQuery];
NSArray *collections = [albumsQuery collections];
for (MPMediaItemCollection *collection in collections)
{
NSDate *collectionReleaseDate = [collection valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"collection release date: %@", collectionReleaseDate);
MPMediaItem *representativeItem = [collection representativeItem];
NSDate *representativeItemReleaseDate = [representativeItem valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"representativeItem release date: %@", representativeItemReleaseDate);
}
// Just per item
MPMediaQuery *query = [[MPMediaQuery alloc] init];
NSArray *items = [query items];
for (MPMediaItem *item in items)
{
NSDate *date = [item valueForProperty: MPMediaItemPropertyReleaseDate];
NSLog(@"release date: %@", date);
}
In all cases I get nil's for NSDates...
But in the iPod library I can see dates, so the information must be available.
What is the correct way to obtain it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,我想我已经明白了。我认为 iTunes 中的“年份”列对应于 API 中的 MPMediaItemPropertyReleaseDate - 但这是错误的。我的物品实际上没有发布日期信息。
我还找到了如何获取“年份”信息(我需要),但不幸的是以无证方式:
Well, I think I've figured it out. I was thinking that 'Year' column in iTunes corresponds to MPMediaItemPropertyReleaseDate in API - but it's wrong. My items actually weren't having release date info.
I also found how to obtain 'Year' information (which I needed), but unfortunately in undocumented way: