AppleScriptのバージョンと同じくらい単純ではありませんが、確かに可能です。
方法1
iTunesライブラリへのポインタを取得します。
iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
SBElementArray *iTunesSources = [iTunesApp sources];
iTunesSource *library;
for (iTunesSource *thisSource in iTunesSources) {
if ([thisSource kind] == iTunesESrcLibrary) {
library = thisSource;
break;
}
}
は、ライブラリ内のすべてのオーディオファイルのトラックを含む配列を取得します。
SBElementArray *libraryPlaylists = [library libraryPlaylists];
iTunesLibraryPlaylist *libraryPlaylist = [libraryPlaylists objectAtIndex:0];
SBElementArray *musicTracks = [self.libraryPlaylist fileTracks];
、フィルタ配列を使用して、探しているタイトルのトラックを探します。 2
NSArray *tracksWithOurTitle = [musicTracks filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%K == %@", @"name", @"Yesterday"]];
// Remember, there might be several tracks with that title; you need to figure out how to find the one you want.
iTunesTrack *rightTrack = [tracksWithOurTitle objectAtIndex:0];
[rightTrack playOnce:YES];
方法は、上記のようにiTunesライブラリへのポインタを取得します。方法2へ
SBElementArray *tracksWithOurTitle = [library searchFor:@"Yesterday" only:kSrS];
// This returns every song whose title *contains* "Yesterday" ...
// You'll need a better way to than this to pick the one you want.
iTunesTrack *rightTrack = [tracksWithOurTitle objectAtIndex:0];
[rightTrack playOnce:YES];
が警告:次にスクリプティングブリッジsearchFor: only:
メソッドを使用iTunes.hが誤ってファイルは、実際には(明白な理由のために)それは* SBElementArrayを返すときsearchFor: only:
方法は、iTunesTrack *を返すと主張しています。ヘッダーファイルを編集して、結果として生じるコンパイラの警告を取り除くことができます。
AppleScriptのバージョンほどシンプルではありませんが、うまくいきます!ありがとう! – Chris
2つの方法(少なくとも私のiTunes.hで)ライブラリはlibraryPlayListでなければならず、kSrSは一重引用符で囲むか、itunes.h定義の列挙型を使用する方が良いことに注意してください。iTunesESrASongs – mackworth