在 NSInteger- Objective C (iPhone) 上使用 MPMediaPlaylistPropertyPlaylistAttributes 和按位运算符

发布于 2024-07-26 06:35:53 字数 1991 浏览 9 评论 0原文

提前感谢您抽出时间。

我正在尝试过滤 iPhone 应用程序的某些类型的播放列表(特别是 Genius 和 On-the-go)。 文档说属性 MPMediaPlaylistPropertyPlaylistAttributes 将以包含 NSInteger 对象的 NSNumber 形式返回与播放列表关联的属性。 该文档还列出了该属性的这些可能值:

e

num {
   MPMediaPlaylistAttributeNone    = 0,
   MPMediaPlaylistAttributeOnTheGo = (1 << 0),
   MPMediaPlaylistAttributeSmart   = (1 << 1),
   MPMediaPlaylistAttributeGenius  = (1 << 2)
};
typedef NSInteger MPMediaPlaylistAttribute;

我想将值记录到终端,因此我使用了

NSLog(@"playlist attribute value:%@", [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] stringValue]);

但是,它每次都会打印出 0 值。 这意味着每个播放列表都具有属性“MPMediaPlaylistAttributeNone”,但这没有意义,因为它也经历了许多天才和移动播放列表。

这是我的整个代码:

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
    NSLog(@"number of playlists total:%d", [[myPlaylistsQuery collections] count]);
    NSArray *playlists = [myPlaylistsQuery collections];

    for (MPMediaPlaylist *playlist in playlists) {

        NSInteger theAttributes;

        theAttributes = [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] integerValue];
        NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist valueForProperty:MPMediaPlaylistPropertyName]);
    }

这是我在 iPhone 上运行该应用程序时的结果。 这些播放列表中的许多实际上都是天才播放列表:

播放列表的属性:0:已购买 播放

列表的属性:0:在我的 iPhone 上购买

播放列表的属性:0:他们的军队

属性:播放列表的 0:蓝色

属性:播放列表的 0:关闭

播放列表的属性:0:疯狂

播放列表的 0:为你疯狂

属性:播放列表的 0:午夜

属性:播放列表的 0:大象之物

属性:播放列表的 0:超大质量黑洞

属性:播放列表的 0:带我走

属性播放列表:0 混合磁带

属性:0 播放列表:时间

属性:0 播放列表:All around me

属性:0 播放列表:anna 的 cd

属性:0 播放列表:Av

属性:0 播放列表:av 2

属性:0播放列表的属性:相信

属性:0 播放列表的属性:BH

属性:0 播放列表的属性:破碎梦想大道

属性:0 播放列表的属性:汽车 1

属性:0 播放列表的属性:汽车 2

属性:0 播放列表的属性:汽车 3

有什么想法为什么每个播放列表属性显示为 0 吗?

再次感谢您的宝贵时间!

and thanks in advance for you time.

I am trying to filter out certain types of playlists for an iphone app (genius and On-the-go, specifically). the documentation says that the property attribute MPMediaPlaylistPropertyPlaylistAttributes will return the attributes associated with a playlist in the form of an NSNumber containing an NSInteger object. The documentation also lists these possible values for that property:

e

num {
   MPMediaPlaylistAttributeNone    = 0,
   MPMediaPlaylistAttributeOnTheGo = (1 << 0),
   MPMediaPlaylistAttributeSmart   = (1 << 1),
   MPMediaPlaylistAttributeGenius  = (1 << 2)
};
typedef NSInteger MPMediaPlaylistAttribute;

I want to log the value to the terminal, so i used

NSLog(@"playlist attribute value:%@", [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] stringValue]);

However, it prints out a value of 0 every time. This means that either every playlist has the attribute "MPMediaPlaylistAttributeNone", but this doesnt make sense since it is going through many genius and on the go playlists as well.

here is my entire code:

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
    NSLog(@"number of playlists total:%d", [[myPlaylistsQuery collections] count]);
    NSArray *playlists = [myPlaylistsQuery collections];

    for (MPMediaPlaylist *playlist in playlists) {

        NSInteger theAttributes;

        theAttributes = [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] integerValue];
        NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist valueForProperty:MPMediaPlaylistPropertyName]);
    }

and here is the result, when i run the application on my iphone. many of these playlists are in fact genius playlists:

attribute:0 of playlist:Purchased

attribute:0 of playlist:Purchased on My iPhone

attribute:0 of playlist:Army of Them

attribute:0 of playlist:Blue

attribute:0 of playlist:Closer

attribute:0 of playlist:Crazy

attribute:0 of playlist:Mad About You

attribute:0 of playlist:Midnight

attribute:0 of playlist:Something Elephants

attribute:0 of playlist:Supermassive Black Hole

attribute:0 of playlist:Take Me Away

attribute:0 of playlist:The Mixed Tape

attribute:0 of playlist:Time

attribute:0 of playlist:All Around Me

attribute:0 of playlist:anna's cd

attribute:0 of playlist:Av

attribute:0 of playlist:av 2

attribute:0 of playlist:Believe

attribute:0 of playlist:BH

attribute:0 of playlist:Boulevard of Broken Dreams

attribute:0 of playlist:car 1

attribute:0 of playlist:car 2

attribute:0 of playlist:car 3

Any ideas why every playlist is coming out as having 0 for the attributes?

Again, thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

白云悠悠 2024-08-02 06:35:53

NSInteger 只是一个原始 typedef:

typedef long NSInteger;

我认为它主要用于避免 32 位/64 位处理器之间的问题。 将其视为常规 int,并在将其传递到字符串格式化程序时使用 %d。 或者只是避免整个问题并使用返回普通 int 的 [val intValue];

An NSInteger is just a primitive typedef:

typedef long NSInteger;

I think it is primarily used to avoid issues between 32bit/64bit processors. Treat it like a regular int, and use %d when passing it into a string formatter. Or just avoid the whole issue and use [val intValue]; which returns a normal int.

阳光的暖冬 2024-08-02 06:35:53

尝试这个。 效果很好。 @i 将打印一个整数

NSInteger theAttributes; theAttributes = [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] integerValue]; NSLog(@"attribute:%i of playlist:%@", theAttributes, [playlist valueForProperty:MPMediaPlaylistPropertyName]);

Try this. It works fine. @i will print an integer

NSInteger theAttributes; theAttributes = [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] integerValue]; NSLog(@"attribute:%i of playlist:%@", theAttributes, [playlist valueForProperty:MPMediaPlaylistPropertyName]);
送舟行 2024-08-02 06:35:53
for (MPMediaPlaylist *playlist in playlists) {

    NSInteger theAttributes =[playlist items].count;

    NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist alueForProperty:MPMediaPlaylistPropertyName]);
};
for (MPMediaPlaylist *playlist in playlists) {

    NSInteger theAttributes =[playlist items].count;

    NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist alueForProperty:MPMediaPlaylistPropertyName]);
};
猥︴琐丶欲为 2024-08-02 06:35:53

NSNumber 不同,NSInteger 不是对象,因此您需要使用 %d 而不是 %@ > 打印出来...

Unlike an NSNumber, a NSInteger isn't an object, so you want to use %d instead of %@ to print it out...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文