如何使用iTunes.h/Scripting Bridge从专辑中获取所有曲目 [英] How to get all tracks from an album using iTunes.h/Scripting Bridge

查看:59
本文介绍了如何使用iTunes.h/Scripting Bridge从专辑中获取所有曲目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用iTunes.h从iTunes上的专辑中获取所有曲目.
现在,我可以通过以下方式获取当前曲目的数据:

I'd like to get all tracks from an album on iTunes using iTunes.h.
Right now I get the data of the current track by:

NSInteger trackID = iTunes.currentTrack.databaseID;
NSString *name  = iTunes.currentTrack.name;

和相册名称的依据:

NSString *trackAlbum = iTunes.currentTrack.album;

但是我不知道如何获取与当前曲目相同专辑中的所有曲目.
有任何想法吗?谢谢

But know I don't know how to get all the tracks that are in the same album as the current track.
Any ideas? Thanks

推荐答案

iTunes API的编写不正确. 您必须使用谓词过滤数组.

The iTunes API is poorly written. You have to filter the array with a predicate.

NSArray *allSongs = [self allSongs];
NSArray *songsOfAlbum = [allSongs filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"album == %@ && artist == %@", albumString, artistString]];

您可以像这样获得所有歌曲:

You can get all the songs like this:

// Get all Songs
- (NSArray *)allSongs {
    if (_allSongs == nil) {

        NSArray *tracksToPlay = [(SBElementArray *)[self.library tracks] get];

        // Sort by artist
        _allSongs = tracksToPlay;
    }

    return _allSongs;
}

- (iTunesLibraryPlaylist *)library {
    if (_library == nil) {
        // Whole Library
        iTunesSource *source = [[[[self.iTunes sources] get] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"kind == %i", iTunesESrcLibrary]] objectAtIndex:0];
        // Only the Music
        _library = [[[[source playlists] get] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"specialKind == %i", iTunesESpKMusic]] objectAtIndex:0];
    }

    return _library;
}

这篇关于如何使用iTunes.h/Scripting Bridge从专辑中获取所有曲目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆