2006-01-20 15:41:31 +00:00
|
|
|
#import "PlaybackController.h"
|
|
|
|
#import "PlaylistView.h"
|
2008-02-12 22:12:27 +00:00
|
|
|
#import <Foundation/NSTimer.h>
|
2007-02-24 20:36:27 +00:00
|
|
|
#import "CogAudio/Status.h"
|
2008-02-17 18:44:11 +00:00
|
|
|
#import "CogAudio/Helper.h"
|
2006-01-20 15:41:31 +00:00
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
#import "PlaylistController.h"
|
|
|
|
#import "PlaylistEntry.h"
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
@implementation PlaybackController
|
|
|
|
|
2008-02-28 13:11:37 +00:00
|
|
|
#define DEFAULT_SEEK 5
|
2008-02-10 18:34:23 +00:00
|
|
|
|
2008-02-23 22:20:14 +00:00
|
|
|
@synthesize playbackStatus;
|
2008-02-13 01:50:39 +00:00
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
2007-02-26 05:26:48 +00:00
|
|
|
[self initDefaults];
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
audioPlayer = [[AudioPlayer alloc] init];
|
|
|
|
[audioPlayer setDelegate:self];
|
2006-01-20 15:41:31 +00:00
|
|
|
playbackStatus = kCogStatusStopped;
|
|
|
|
|
|
|
|
showTimeRemaining = NO;
|
2007-02-25 02:43:56 +00:00
|
|
|
|
|
|
|
scrobbler = [[AudioScrobbler alloc] init];
|
2007-02-28 00:35:27 +00:00
|
|
|
[GrowlApplicationBridge setGrowlDelegate:self];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-02-26 05:26:48 +00:00
|
|
|
- (void)initDefaults
|
|
|
|
{
|
|
|
|
NSDictionary *defaultsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithBool:YES], @"enableAudioScrobbler",
|
|
|
|
[NSNumber numberWithBool:NO], @"automaticallyLaunchLastFM",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
|
|
|
}
|
|
|
|
|
2007-02-28 00:35:27 +00:00
|
|
|
- (NSDictionary *) registrationDictionaryForGrowl
|
|
|
|
{
|
|
|
|
NSArray *notifications = [NSArray arrayWithObjects:@"Stream Changed", nil];
|
|
|
|
|
|
|
|
return [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"Cog", GROWL_APP_NAME,
|
|
|
|
notifications, GROWL_NOTIFICATIONS_ALL,
|
|
|
|
notifications, GROWL_NOTIFICATIONS_DEFAULT,
|
|
|
|
nil];
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:50:39 +00:00
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2008-02-13 01:50:39 +00:00
|
|
|
|
|
|
|
[volumeSlider setDoubleValue:logarithmicToLinear(100.0)];
|
|
|
|
[audioPlayer setVolume: 100];
|
2008-02-12 22:12:27 +00:00
|
|
|
|
2007-07-05 23:08:10 +00:00
|
|
|
[positionSlider setEnabled:NO];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
2007-02-20 01:02:23 +00:00
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
- (IBAction)playPauseResume:(id)sender
|
|
|
|
{
|
|
|
|
if (playbackStatus == kCogStatusStopped)
|
2008-02-22 03:09:03 +00:00
|
|
|
{
|
2006-01-20 15:41:31 +00:00
|
|
|
[self play:self];
|
2008-02-22 03:09:03 +00:00
|
|
|
}
|
2006-01-20 15:41:31 +00:00
|
|
|
else
|
2008-02-22 03:09:03 +00:00
|
|
|
{
|
2006-01-20 15:41:31 +00:00
|
|
|
[self pauseResume:self];
|
2008-02-22 03:09:03 +00:00
|
|
|
}
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)pauseResume:(id)sender
|
|
|
|
{
|
|
|
|
if (playbackStatus == kCogStatusPaused)
|
|
|
|
[self resume:self];
|
|
|
|
else
|
|
|
|
[self pause:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)pause:(id)sender
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
[audioPlayer pause];
|
2008-02-16 16:30:18 +00:00
|
|
|
playbackStatus = kCogStatusPaused;
|
2007-02-25 02:43:56 +00:00
|
|
|
|
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
|
|
|
[scrobbler pause];
|
|
|
|
}
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)resume:(id)sender
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
[audioPlayer resume];
|
2007-02-25 02:43:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
|
|
|
[scrobbler resume];
|
|
|
|
}
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)stop:(id)sender
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
[audioPlayer stop];
|
2007-02-25 02:43:56 +00:00
|
|
|
|
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
|
|
|
[scrobbler stop];
|
|
|
|
}
|
2007-02-28 00:35:27 +00:00
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//called by double-clicking on table
|
|
|
|
- (void)playEntryAtIndex:(int)i
|
|
|
|
{
|
2008-02-20 13:20:07 +00:00
|
|
|
PlaylistEntry *pe = [playlistController entryAtIndex:i];
|
2006-01-20 15:41:31 +00:00
|
|
|
|
|
|
|
[self playEntry:pe];
|
|
|
|
}
|
|
|
|
|
2007-11-01 01:53:52 +00:00
|
|
|
|
|
|
|
- (IBAction)playbackButtonClick:(id)sender
|
|
|
|
{
|
|
|
|
int clickedSegment = [sender selectedSegment];
|
|
|
|
if (clickedSegment == 0) //Previous
|
|
|
|
{
|
|
|
|
[self prev:sender];
|
|
|
|
}
|
|
|
|
else if (clickedSegment == 1) //Play
|
|
|
|
{
|
|
|
|
[self playPauseResume:sender];
|
|
|
|
}
|
|
|
|
else if (clickedSegment == 2) //Next
|
|
|
|
{
|
|
|
|
[self next:sender];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
- (IBAction)play:(id)sender
|
|
|
|
{
|
|
|
|
if ([playlistView selectedRow] == -1)
|
2008-11-21 15:14:23 +00:00
|
|
|
[playlistView selectRow:0 byExtendingSelection:NO];
|
2008-11-21 15:43:34 +00:00
|
|
|
|
|
|
|
if ([playlistView selectedRow] > -1)
|
2008-11-21 15:14:23 +00:00
|
|
|
[self playEntryAtIndex:[playlistView selectedRow]];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
2007-02-25 02:43:56 +00:00
|
|
|
- (void)playEntry:(PlaylistEntry *)pe
|
2006-01-20 15:41:31 +00:00
|
|
|
{
|
2006-01-29 14:57:48 +00:00
|
|
|
if (playbackStatus != kCogStatusStopped)
|
|
|
|
[self stop:self];
|
2006-05-13 15:52:52 +00:00
|
|
|
|
2008-02-22 03:09:03 +00:00
|
|
|
NSLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]);
|
|
|
|
[playlistController setCurrentEntry:pe];
|
2006-04-02 15:44:08 +00:00
|
|
|
|
2008-02-22 03:09:03 +00:00
|
|
|
[positionSlider setDoubleValue:0.0];
|
2006-04-02 15:44:08 +00:00
|
|
|
[self updateTimeField:0.0f];
|
2008-02-22 03:09:03 +00:00
|
|
|
|
|
|
|
if (pe == nil)
|
|
|
|
return;
|
2006-04-02 15:44:08 +00:00
|
|
|
|
2008-02-20 00:44:40 +00:00
|
|
|
[audioPlayer play:[pe URL] withUserInfo:pe];
|
2007-02-25 02:43:56 +00:00
|
|
|
|
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
|
|
|
[scrobbler start:pe];
|
|
|
|
}
|
2007-02-28 00:35:27 +00:00
|
|
|
|
2007-02-28 02:03:37 +00:00
|
|
|
[GrowlApplicationBridge notifyWithTitle:[pe title]
|
|
|
|
description:[pe artist]
|
|
|
|
notificationName:@"Stream Changed"
|
|
|
|
iconData:nil
|
|
|
|
priority:0
|
|
|
|
isSticky:NO
|
|
|
|
clickContext:nil];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)next:(id)sender
|
|
|
|
{
|
2006-01-29 14:57:48 +00:00
|
|
|
if ([playlistController next] == NO)
|
2006-01-20 15:41:31 +00:00
|
|
|
return;
|
2006-01-29 14:57:48 +00:00
|
|
|
|
2007-06-05 03:09:55 +00:00
|
|
|
[self playEntry:[playlistController currentEntry]];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)prev:(id)sender
|
|
|
|
{
|
2008-02-14 23:09:51 +00:00
|
|
|
if ([playlistController prev] == NO)
|
2006-01-20 15:41:31 +00:00
|
|
|
return;
|
|
|
|
|
2007-06-05 03:09:55 +00:00
|
|
|
[self playEntry:[playlistController currentEntry]];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)seek:(id)sender
|
|
|
|
{
|
|
|
|
double time;
|
|
|
|
time = [positionSlider doubleValue];
|
2006-04-18 17:00:29 +00:00
|
|
|
|
2006-04-04 01:08:21 +00:00
|
|
|
if ([sender tracking] == NO) // check if user stopped sliding before playing audio
|
2007-02-24 20:36:27 +00:00
|
|
|
[audioPlayer seekToTime:time];
|
2006-01-20 15:41:31 +00:00
|
|
|
|
|
|
|
[self updateTimeField:time];
|
|
|
|
}
|
|
|
|
|
2008-02-13 18:03:06 +00:00
|
|
|
- (IBAction)eventSeekForward:(id)sender
|
2008-02-07 23:57:21 +00:00
|
|
|
{
|
2008-02-13 18:03:06 +00:00
|
|
|
[self seekForward:DEFAULT_SEEK];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)seekForward:(double)amount
|
|
|
|
{
|
|
|
|
double seekTo = [audioPlayer amountPlayed] + amount;
|
2008-02-10 18:34:23 +00:00
|
|
|
|
|
|
|
if (seekTo > (int)[positionSlider maxValue])
|
2008-02-07 23:57:21 +00:00
|
|
|
{
|
|
|
|
[self next:self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-10 18:34:23 +00:00
|
|
|
[audioPlayer seekToTime:seekTo];
|
|
|
|
[self updateTimeField:seekTo];
|
|
|
|
[positionSlider setDoubleValue:seekTo];
|
2008-02-07 23:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-13 18:03:06 +00:00
|
|
|
- (IBAction)eventSeekBackward:(id)sender
|
|
|
|
{
|
|
|
|
[self seekBackward:DEFAULT_SEEK];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)seekBackward:(double)amount
|
2008-02-07 23:57:21 +00:00
|
|
|
{
|
2008-02-13 18:03:06 +00:00
|
|
|
double seekTo = [audioPlayer amountPlayed] - amount;
|
2008-02-10 18:34:23 +00:00
|
|
|
|
|
|
|
if (seekTo < 0)
|
2008-02-17 18:44:11 +00:00
|
|
|
seekTo = 0;
|
|
|
|
|
|
|
|
[audioPlayer seekToTime:seekTo];
|
|
|
|
[self updateTimeField:seekTo];
|
|
|
|
[positionSlider setDoubleValue:seekTo];
|
2008-02-07 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
- (void)changePlayButtonImage:(NSString *)name
|
|
|
|
{
|
2007-11-01 01:53:52 +00:00
|
|
|
NSImage *img = [NSImage imageNamed:name];
|
|
|
|
// [img retain];
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
if (img == nil)
|
|
|
|
{
|
2007-07-11 01:20:32 +00:00
|
|
|
NSLog(@"Error loading image!");
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
2007-11-01 01:53:52 +00:00
|
|
|
[playbackButtons setImage:img forSegment:1];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)changeVolume:(id)sender
|
|
|
|
{
|
2008-02-13 01:50:39 +00:00
|
|
|
NSLog(@"VOLUME: %lf, %lf", [sender doubleValue], linearToLogarithmic([sender doubleValue]));
|
|
|
|
|
|
|
|
[audioPlayer setVolume:linearToLogarithmic([sender doubleValue])];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
2008-02-12 22:12:27 +00:00
|
|
|
/* selector for NSTimer - gets passed the Timer object itself
|
|
|
|
and the appropriate userInfo, which in this case is an NSNumber
|
|
|
|
containing the current volume before we start fading. */
|
2008-02-16 16:30:18 +00:00
|
|
|
- (void)audioFadeDown:(NSTimer *)audioTimer
|
2008-02-12 22:12:27 +00:00
|
|
|
{
|
2008-02-13 01:50:39 +00:00
|
|
|
double volume = [audioPlayer volume];
|
|
|
|
double originalVolume = [[audioTimer userInfo] doubleValue];
|
2008-02-17 18:44:11 +00:00
|
|
|
double down = originalVolume/10;
|
|
|
|
|
2008-02-13 01:50:39 +00:00
|
|
|
NSLog(@"VOLUME IS %lf", volume);
|
2008-02-13 18:03:06 +00:00
|
|
|
|
2008-02-13 01:50:39 +00:00
|
|
|
if (volume > 0.0001) //YAY! Roundoff error!
|
2008-02-12 22:12:27 +00:00
|
|
|
{
|
2008-02-17 18:44:11 +00:00
|
|
|
[audioPlayer volumeDown:down];
|
2008-02-12 22:12:27 +00:00
|
|
|
}
|
|
|
|
else // volume is at 0 or below, we are ready to release the timer and move on
|
|
|
|
{
|
|
|
|
[audioPlayer pause];
|
2008-02-13 01:50:39 +00:00
|
|
|
[audioPlayer setVolume:originalVolume];
|
|
|
|
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume)];
|
2008-02-12 22:12:27 +00:00
|
|
|
[audioTimer invalidate];
|
2008-02-23 22:20:14 +00:00
|
|
|
playbackStatus = kCogStatusPaused;
|
2008-02-12 22:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-16 16:30:18 +00:00
|
|
|
- (void)audioFadeUp:(NSTimer *)audioTimer
|
|
|
|
{
|
|
|
|
double volume = [audioPlayer volume];
|
|
|
|
double originalVolume = [[audioTimer userInfo] doubleValue];
|
2008-02-17 18:44:11 +00:00
|
|
|
double up = originalVolume/10;
|
|
|
|
|
2008-02-16 16:30:18 +00:00
|
|
|
NSLog(@"VOLUME IS %lf", volume);
|
|
|
|
|
|
|
|
if (volume < originalVolume)
|
|
|
|
{
|
2008-02-17 18:44:11 +00:00
|
|
|
if ((volume + up) > originalVolume)
|
|
|
|
[audioPlayer volumeUp:(originalVolume - volume)];
|
2008-02-16 16:30:18 +00:00
|
|
|
else
|
2008-02-17 18:44:11 +00:00
|
|
|
[audioPlayer volumeUp:up];
|
2008-02-16 16:30:18 +00:00
|
|
|
}
|
|
|
|
else // volume is at 0 or below, we are ready to release the timer and move on
|
|
|
|
{
|
|
|
|
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume)];
|
|
|
|
[audioTimer invalidate];
|
2008-02-23 22:20:14 +00:00
|
|
|
playbackStatus = kCogStatusPlaying;
|
2008-02-16 16:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-23 22:20:14 +00:00
|
|
|
- (IBAction)fade:(id)sender
|
2008-02-12 22:12:27 +00:00
|
|
|
{
|
2008-02-23 22:20:14 +00:00
|
|
|
double time = 0.1;
|
|
|
|
|
2008-02-13 18:03:06 +00:00
|
|
|
// we can not allow multiple fade timers to be registered
|
2008-02-16 16:30:18 +00:00
|
|
|
if (playbackStatus == kCogStatusFading)
|
2008-02-13 18:03:06 +00:00
|
|
|
return;
|
2008-02-16 16:30:18 +00:00
|
|
|
|
2008-02-13 18:03:06 +00:00
|
|
|
NSNumber *originalVolume = [NSNumber numberWithDouble: [audioPlayer volume]];
|
|
|
|
NSTimer *fadeTimer;
|
|
|
|
|
2008-02-16 16:30:18 +00:00
|
|
|
if (playbackStatus == kCogStatusPlaying)
|
|
|
|
fadeTimer = [NSTimer scheduledTimerWithTimeInterval:time
|
2008-02-12 22:12:27 +00:00
|
|
|
target:self
|
2008-02-16 16:30:18 +00:00
|
|
|
selector:@selector(audioFadeDown:)
|
2008-02-13 01:50:39 +00:00
|
|
|
userInfo:originalVolume
|
2008-02-12 22:12:27 +00:00
|
|
|
repeats:YES];
|
2008-02-16 16:30:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[audioPlayer setVolume:0];
|
|
|
|
fadeTimer = [NSTimer scheduledTimerWithTimeInterval:time
|
|
|
|
target:self
|
|
|
|
selector:@selector(audioFadeUp:)
|
|
|
|
userInfo:originalVolume
|
|
|
|
repeats:YES];
|
|
|
|
[self pauseResume:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
playbackStatus = kCogStatusFading;
|
|
|
|
|
2008-02-12 22:12:27 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 19:25:01 +00:00
|
|
|
- (IBAction)skipToNextAlbum:(id)sender
|
|
|
|
{
|
|
|
|
BOOL found = NO;
|
|
|
|
|
2008-02-23 22:20:14 +00:00
|
|
|
int index = [[playlistController currentEntry] index];
|
2008-02-20 00:12:25 +00:00
|
|
|
NSString *origAlbum = [[playlistController currentEntry] album];
|
2008-02-14 19:25:01 +00:00
|
|
|
|
2008-02-20 13:20:07 +00:00
|
|
|
int i;
|
2008-02-14 19:25:01 +00:00
|
|
|
NSString *curAlbum;
|
|
|
|
|
|
|
|
PlaylistEntry *pe;
|
|
|
|
|
2008-02-20 13:20:07 +00:00
|
|
|
for (i = 1; i < [[playlistController arrangedObjects] count]; i++)
|
2008-02-14 19:25:01 +00:00
|
|
|
{
|
2008-02-23 22:20:14 +00:00
|
|
|
pe = [playlistController entryAtIndex:index + i];
|
|
|
|
if (pe == nil)
|
2008-02-20 13:20:07 +00:00
|
|
|
break;
|
|
|
|
|
2008-02-14 19:25:01 +00:00
|
|
|
curAlbum = [pe album];
|
|
|
|
|
|
|
|
// check for untagged files, and just play the first untagged one
|
|
|
|
// we come across
|
|
|
|
if (curAlbum == nil)
|
|
|
|
{
|
2008-02-20 13:20:07 +00:00
|
|
|
found = YES;
|
|
|
|
break;
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
2008-02-20 13:20:07 +00:00
|
|
|
|
2008-02-20 13:25:24 +00:00
|
|
|
if ([curAlbum caseInsensitiveCompare:origAlbum] != NSOrderedSame)
|
2008-02-14 19:25:01 +00:00
|
|
|
{
|
|
|
|
found = YES;
|
2008-02-20 13:20:07 +00:00
|
|
|
break;
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 13:20:07 +00:00
|
|
|
if (found)
|
|
|
|
{
|
2008-02-23 22:20:14 +00:00
|
|
|
[self playEntryAtIndex:i + index];
|
2008-02-20 13:20:07 +00:00
|
|
|
}
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)skipToPreviousAlbum:(id)sender
|
|
|
|
{
|
2008-02-20 13:20:07 +00:00
|
|
|
BOOL found = NO;
|
2008-02-14 19:25:01 +00:00
|
|
|
BOOL foundAlbum = NO;
|
|
|
|
|
2008-02-23 22:20:14 +00:00
|
|
|
int index = [[playlistController currentEntry] index];
|
2008-02-20 00:12:25 +00:00
|
|
|
NSString *origAlbum = [[playlistController currentEntry] album];
|
2008-02-14 19:25:01 +00:00
|
|
|
NSString *curAlbum;
|
|
|
|
|
2008-02-20 13:20:07 +00:00
|
|
|
int i;
|
2008-02-14 19:25:01 +00:00
|
|
|
|
|
|
|
PlaylistEntry *pe;
|
2008-02-20 13:20:07 +00:00
|
|
|
|
|
|
|
for (i = 1; i < [[playlistController arrangedObjects] count]; i++)
|
2008-02-14 19:25:01 +00:00
|
|
|
{
|
2008-02-23 22:20:14 +00:00
|
|
|
pe = [playlistController entryAtIndex:index - i];
|
|
|
|
if (pe == nil)
|
2008-02-20 13:20:07 +00:00
|
|
|
break;
|
2008-02-23 22:20:14 +00:00
|
|
|
|
2008-02-14 19:25:01 +00:00
|
|
|
curAlbum = [pe album];
|
|
|
|
if (curAlbum == nil)
|
|
|
|
{
|
2008-02-20 13:20:07 +00:00
|
|
|
found = YES;
|
|
|
|
break;
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
2008-02-20 13:20:07 +00:00
|
|
|
|
2008-02-20 13:25:24 +00:00
|
|
|
if ([curAlbum caseInsensitiveCompare:origAlbum] != NSOrderedSame)
|
2008-02-14 19:25:01 +00:00
|
|
|
{
|
|
|
|
if (foundAlbum == NO)
|
|
|
|
{
|
|
|
|
foundAlbum = YES;
|
2008-02-15 15:27:34 +00:00
|
|
|
// now we need to move up to the first song in the album, so we'll
|
|
|
|
// go till we either find index 0, or the first song in the album
|
2008-02-20 13:20:07 +00:00
|
|
|
origAlbum = curAlbum;
|
|
|
|
continue;
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
|
|
|
else
|
2008-02-20 13:20:07 +00:00
|
|
|
{
|
2008-02-14 19:25:01 +00:00
|
|
|
found = YES; // terminate loop
|
2008-02-20 13:20:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 13:20:07 +00:00
|
|
|
if (found || foundAlbum)
|
|
|
|
{
|
|
|
|
if (foundAlbum == YES)
|
|
|
|
i--;
|
2008-02-23 22:20:14 +00:00
|
|
|
[self playEntryAtIndex:index - i];
|
2008-02-20 13:20:07 +00:00
|
|
|
}
|
2008-02-14 19:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-17 18:44:11 +00:00
|
|
|
- (IBAction)volumeDown:(id)sender
|
2007-02-18 23:41:44 +00:00
|
|
|
{
|
2008-02-13 18:03:06 +00:00
|
|
|
double newVolume;
|
2008-02-17 18:44:11 +00:00
|
|
|
newVolume = [audioPlayer volumeDown:DEFAULT_VOLUME_DOWN];
|
2008-02-13 01:50:39 +00:00
|
|
|
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
2007-02-18 23:41:44 +00:00
|
|
|
|
2008-02-13 18:03:06 +00:00
|
|
|
}
|
2008-02-12 22:12:27 +00:00
|
|
|
|
2008-02-17 18:44:11 +00:00
|
|
|
- (IBAction)volumeUp:(id)sender
|
|
|
|
{
|
|
|
|
double newVolume;
|
|
|
|
newVolume = [audioPlayer volumeUp:DEFAULT_VOLUME_UP];
|
2008-02-13 01:50:39 +00:00
|
|
|
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
2008-02-17 18:44:11 +00:00
|
|
|
|
2007-02-18 23:41:44 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
|
|
|
|
- (void)updateTimeField:(double)pos
|
|
|
|
{
|
|
|
|
NSString *text;
|
|
|
|
if (showTimeRemaining == NO)
|
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
int sec = (int)(pos);
|
2006-01-20 15:41:31 +00:00
|
|
|
text = [NSString stringWithFormat:NSLocalizedString(@"TimeElapsed", @""), sec/60, sec%60];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
int sec = (int)(([positionSlider maxValue] - pos));
|
2006-05-13 16:50:52 +00:00
|
|
|
if (sec < 0)
|
|
|
|
sec = 0;
|
2006-01-20 15:41:31 +00:00
|
|
|
text = [NSString stringWithFormat:NSLocalizedString(@"TimeRemaining", @""), sec/60, sec%60];
|
|
|
|
}
|
|
|
|
[timeField setStringValue:text];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)toggleShowTimeRemaining:(id)sender
|
|
|
|
{
|
|
|
|
showTimeRemaining = !showTimeRemaining;
|
|
|
|
|
|
|
|
[self updateTimeField:[positionSlider doubleValue]];
|
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (void)audioPlayer:(AudioPlayer *)player requestNextStream:(id)userInfo
|
2006-01-20 15:41:31 +00:00
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
|
2008-02-25 17:02:06 +00:00
|
|
|
PlaylistEntry *pe;
|
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
if (curEntry.stopAfter)
|
2008-02-26 11:59:47 +00:00
|
|
|
pe = nil;
|
2008-02-25 17:02:06 +00:00
|
|
|
else
|
|
|
|
pe = [playlistController getNextEntry:curEntry];
|
2006-05-12 18:12:31 +00:00
|
|
|
|
2008-02-20 00:44:40 +00:00
|
|
|
[player setNextStream:[pe URL] withUserInfo:pe];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (void)audioPlayer:(AudioPlayer *)player streamChanged:(id)userInfo
|
2006-01-20 15:41:31 +00:00
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
PlaylistEntry *pe = (PlaylistEntry *)userInfo;
|
|
|
|
|
2006-04-13 02:51:22 +00:00
|
|
|
[playlistController setCurrentEntry:pe];
|
2006-01-20 15:41:31 +00:00
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
[positionSlider setDoubleValue:0.0f];
|
2006-01-20 15:41:31 +00:00
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
[self updateTimeField:0.0f];
|
2006-01-20 15:41:31 +00:00
|
|
|
|
2007-02-25 02:43:56 +00:00
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
|
|
|
[scrobbler start:pe];
|
|
|
|
}
|
2007-02-28 00:35:27 +00:00
|
|
|
|
2007-02-28 02:03:37 +00:00
|
|
|
[GrowlApplicationBridge notifyWithTitle:[pe title]
|
|
|
|
description:[pe artist]
|
|
|
|
notificationName:@"Stream Changed"
|
|
|
|
iconData:nil
|
|
|
|
priority:0
|
|
|
|
isSticky:NO
|
|
|
|
clickContext:nil];
|
2006-01-20 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
- (void)updatePosition:(id)sender
|
2006-01-20 15:41:31 +00:00
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
double pos = [audioPlayer amountPlayed];
|
2006-04-02 15:44:08 +00:00
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
if ([positionSlider tracking] == NO)
|
|
|
|
{
|
|
|
|
[positionSlider setDoubleValue:pos];
|
|
|
|
[self updateTimeField:pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (void)audioPlayer:(AudioPlayer *)player statusChanged:(id)s
|
2006-01-20 15:41:31 +00:00
|
|
|
{
|
2006-01-29 14:57:48 +00:00
|
|
|
int status = [s intValue];
|
2006-01-20 15:41:31 +00:00
|
|
|
if (status == kCogStatusStopped || status == kCogStatusPaused)
|
|
|
|
{
|
2006-04-02 15:44:08 +00:00
|
|
|
if (positionTimer)
|
|
|
|
{
|
|
|
|
[positionTimer invalidate];
|
|
|
|
positionTimer = NULL;
|
|
|
|
}
|
|
|
|
if (status == kCogStatusStopped)
|
|
|
|
{
|
|
|
|
[positionSlider setDoubleValue:0.0f];
|
2008-11-21 15:14:23 +00:00
|
|
|
[positionSlider setEnabled:NO]; // the player stopped, disable the slider
|
|
|
|
[self updateTimeField:0.0f];
|
2006-04-02 15:44:08 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
//Show play image
|
|
|
|
[self changePlayButtonImage:@"play"];
|
|
|
|
}
|
|
|
|
else if (status == kCogStatusPlaying)
|
|
|
|
{
|
2006-04-02 15:44:08 +00:00
|
|
|
if (!positionTimer)
|
|
|
|
positionTimer = [NSTimer scheduledTimerWithTimeInterval:1.00 target:self selector:@selector(updatePosition:) userInfo:nil repeats:YES];
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
//Show pause
|
|
|
|
[self changePlayButtonImage:@"pause"];
|
|
|
|
}
|
|
|
|
|
2007-06-03 17:09:07 +00:00
|
|
|
if (status == kCogStatusStopped) {
|
2008-02-22 03:46:04 +00:00
|
|
|
NSLog(@"DONE!");
|
2008-02-22 03:09:03 +00:00
|
|
|
[playlistController setCurrentEntry:nil];
|
2008-11-21 15:14:23 +00:00
|
|
|
[positionSlider setEnabled:NO]; // the player stopped, disable the slider
|
2007-06-03 17:09:07 +00:00
|
|
|
}
|
2008-02-22 03:46:04 +00:00
|
|
|
else {
|
|
|
|
NSLog(@"PLAYING!");
|
|
|
|
}
|
2008-02-22 03:09:03 +00:00
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
playbackStatus = status;
|
|
|
|
}
|
|
|
|
|
2008-02-10 18:34:23 +00:00
|
|
|
|
|
|
|
|
2006-01-20 15:41:31 +00:00
|
|
|
@end
|