获取 iPod 库中项目的专辑年份?

发布于 2024-10-15 09:44:38 字数 983 浏览 3 评论 0原文

尝试以下代码:

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-10-22 09:44:38

嗯,我想我已经明白了。我认为 iTunes 中的“年份”列对应于 API 中的 MPMediaItemPropertyReleaseDate - 但这是错误的。我的物品实际上没有发布日期信息。

我还找到了如何获取“年份”信息(我需要),但不幸的是以无证方式:

MPMediaItem *item = ...;
NSNumber *yearNumber = [item valueForProperty:@"year"];
if (yearNumber && [yearNumber isKindOfClass:[NSNumber class]])
{
    int year = [yearNumber intValue];
    if (year != 0)
    {
        // do something with year
    }
}

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:

MPMediaItem *item = ...;
NSNumber *yearNumber = [item valueForProperty:@"year"];
if (yearNumber && [yearNumber isKindOfClass:[NSNumber class]])
{
    int year = [yearNumber intValue];
    if (year != 0)
    {
        // do something with year
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文