Created
August 18, 2014 05:52
-
-
Save imack/a4011144108a55462761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TunesTableViewController.m | |
// ItunesPlay | |
// | |
// Created by Ian MacKinnon on 2014-08-17. | |
// Copyright (c) 2014 Ian MacKinnon. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import <MediaPlayer/MediaPlayer.h> | |
#import "TunesTableViewController.h" | |
@interface TunesTableViewController (){ | |
MPMusicPlayerController *musicPlayer; | |
NSArray *collections; | |
} | |
@end | |
@implementation TunesTableViewController | |
- (id)initWithStyle:(UITableViewStyle)style | |
{ | |
self = [super initWithStyle:style]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
musicPlayer = [MPMusicPlayerController iPodMusicPlayer]; | |
MPMediaQuery *everything = [[MPMediaQuery alloc] init]; | |
collections = [everything items]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
#pragma mark - Table view data source | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
{ | |
// Return the number of sections. | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
{ | |
// Return the number of rows in the section. | |
return [collections count]; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MediaEntry" forIndexPath:indexPath]; | |
MPMediaItem *entity= [collections objectAtIndex:indexPath.row]; | |
NSString *title = [entity valueForProperty:MPMediaItemPropertyTitle]; | |
[cell.textLabel setText:title]; | |
return cell; | |
} | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
// Navigation logic may go here. Create and push another view controller. | |
MPMediaItem *entity= [collections objectAtIndex:indexPath.row]; | |
MPMediaItemCollection *collection = [[MPMediaItemCollection alloc] initWithItems:collections]; | |
[musicPlayer setQueueWithItemCollection:collection]; | |
[musicPlayer setNowPlayingItem:entity]; | |
[musicPlayer prepareToPlay]; | |
[musicPlayer play]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment