forked from erica/MPMediaItem-Properties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
executable file
·87 lines (74 loc) · 2.77 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook, 3.0 Edition
BSD License, Use at your own risk
*/
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "MPMediaItem-Properties.h"
#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]
@interface TestBedViewController : UIViewController
{
NSMutableString *log;
IBOutlet UITextView *textView;
}
@property (retain) NSMutableString *log;
@end
@implementation TestBedViewController
@synthesize log;
- (void) doLog: (NSString *) formatstring, ...
{
va_list arglist;
if (!formatstring) return;
va_start(arglist, formatstring);
NSString *outstring = [[[NSString alloc] initWithFormat:formatstring arguments:arglist] autorelease];
va_end(arglist);
[self.log appendString:outstring];
[self.log appendString:@"\n"];
textView.text = self.log;
}
- (void) action: (UIBarButtonItem *) bbi
{
self.log = [NSMutableString string];
MPMediaQuery *query = [MPMediaQuery songsQuery];
MPMediaPropertyPredicate *mpp = [MPMediaPropertyPredicate
predicateWithValue:@"road"
forProperty:MPMediaItemPropertyTitle
comparisonType:MPMediaPredicateComparisonContains];
[query addFilterPredicate:mpp];
NSArray *collections = query.collections;
[self doLog:@"You have %d matching tracks in your library\n", collections.count];
for (MPMediaItemCollection *collection in collections)
{
for (MPMediaItem *item in [collection items])
[self doLog:@"%@, %@", item.title, item.artist];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"artist contains[cd] %@", @"Joel"];
NSArray *array = [[collection items] filteredArrayUsingPredicate:pred];
for (MPMediaItem *item in array)
[self doLog:@"Filtered: %@ %@", item.title, item.artist];
}
}
- (void) viewDidLoad
{
self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Action", @selector(action:));
}
@end
@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>
@end
@implementation TestBedAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TestBedViewController alloc] init]];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}
@end
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
[pool release];
return retVal;
}