mirror of
https://github.com/samsonjs/5by5Browser.git
synced 2026-03-25 09:05:50 +00:00
keep the currently playing track, er... current
This commit is contained in:
parent
f485ed3697
commit
50e2176d75
3 changed files with 25 additions and 13 deletions
Binary file not shown.
|
|
@ -18,6 +18,7 @@
|
||||||
@property (nonatomic, retain) Show *currentShow;
|
@property (nonatomic, retain) Show *currentShow;
|
||||||
@property (nonatomic, retain) NSString *currentEpisodeNumber;
|
@property (nonatomic, retain) NSString *currentEpisodeNumber;
|
||||||
@property (nonatomic, retain) NSString *currentEpisodeName;
|
@property (nonatomic, retain) NSString *currentEpisodeName;
|
||||||
|
@property (nonatomic, retain) NSTimer *checkNowPlayingTimer;
|
||||||
|
|
||||||
- (void) checkNowPlaying;
|
- (void) checkNowPlaying;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
@synthesize currentShow = _currentShow;
|
@synthesize currentShow = _currentShow;
|
||||||
@synthesize currentEpisodeNumber = _currentEpisodeNumber;
|
@synthesize currentEpisodeNumber = _currentEpisodeNumber;
|
||||||
@synthesize currentEpisodeName = _currentEpisodeName;
|
@synthesize currentEpisodeName = _currentEpisodeName;
|
||||||
|
@synthesize checkNowPlayingTimer = _checkNowPlayingTimer;
|
||||||
|
|
||||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +49,19 @@
|
||||||
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self checkNowPlaying];
|
self.checkNowPlayingTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0
|
||||||
|
target: self
|
||||||
|
selector: @selector(checkNowPlaying)
|
||||||
|
userInfo: nil
|
||||||
|
repeats: YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) viewWillDisappear: (BOOL)animated
|
||||||
|
{
|
||||||
|
[super viewWillDisappear: animated];
|
||||||
|
|
||||||
|
[self.checkNowPlayingTimer invalidate];
|
||||||
|
self.checkNowPlayingTimer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||||
|
|
@ -66,20 +79,18 @@
|
||||||
MPMediaItem *song = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
|
MPMediaItem *song = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
|
||||||
if (song) {
|
if (song) {
|
||||||
NSString *title = [song valueForProperty: MPMediaItemPropertyTitle];
|
NSString *title = [song valueForProperty: MPMediaItemPropertyTitle];
|
||||||
self.currentEpisodeNumber = [title firstMatch: @"\\d+"];
|
NSString *episodeNumber = [title firstMatch: @"\\d+"];
|
||||||
self.currentEpisodeName = [title substringFromIndex: [title rangeOfString: @": "].location + 2];
|
|
||||||
NSString *showName = [song valueForProperty: MPMediaItemPropertyAlbumTitle];
|
NSString *showName = [song valueForProperty: MPMediaItemPropertyAlbumTitle];
|
||||||
self.currentShow = [self.fiveByFive showWithName: showName];
|
if (![self.currentEpisodeNumber isEqualToString: episodeNumber] && ![self.currentShow.name isEqualToString: showName]) {
|
||||||
if (self.currentShow) {
|
Show *nowPlayingShow = [self.fiveByFive showWithName: showName];
|
||||||
NSLog(@"show: %@, episode: %@, name: %@", showName, self.currentEpisodeNumber, self.currentEpisodeName);
|
if (nowPlayingShow) {
|
||||||
NSLog(@"show url: %@", [self.currentShow webURLForEpisodeNumber: self.currentEpisodeNumber]);
|
self.currentShow = nowPlayingShow;
|
||||||
|
self.currentEpisodeNumber = episodeNumber;
|
||||||
|
self.currentEpisodeName = [title substringFromIndex: [title rangeOfString: @": "].location + 2];
|
||||||
|
NSLog(@"show: %@, episode: %@, name: %@", showName, self.currentEpisodeNumber, self.currentEpisodeName);
|
||||||
|
NSLog(@"show url: %@", [self.currentShow webURLForEpisodeNumber: self.currentEpisodeNumber]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
NSLog(@"no show named %@", showName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"no song is currently playing");
|
|
||||||
}
|
}
|
||||||
[self.tableView reloadData];
|
[self.tableView reloadData];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue