2009-02-28 21:13:06 +00:00
|
|
|
//
|
|
|
|
// PlaybackButtons.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 2/28/09.
|
|
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "PlaybackButtons.h"
|
|
|
|
#import "PlaybackController.h"
|
|
|
|
|
|
|
|
#import <CogAudio/Status.h>
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2009-02-28 21:13:06 +00:00
|
|
|
@implementation PlaybackButtons
|
|
|
|
|
|
|
|
static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackButtonsPlaybackStatusObservationContext";
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self stopObserving];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[self startObserving];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startObserving
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void * _Nullable)(PlaybackButtonsPlaybackStatusObservationContext)];
|
2009-02-28 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopObserving
|
|
|
|
{
|
|
|
|
[playbackController removeObserver:self forKeyPath:@"playbackStatus"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
if ([PlaybackButtonsPlaybackStatusObservationContext isEqual:(__bridge id)(context)])
|
2009-02-28 21:13:06 +00:00
|
|
|
{
|
|
|
|
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
|
|
|
|
|
|
|
NSImage *image = nil;
|
|
|
|
|
2009-02-28 21:19:26 +00:00
|
|
|
if (playbackStatus == kCogStatusPlaying) {
|
2020-11-23 02:16:34 +00:00
|
|
|
image = [NSImage imageNamed:@"pauseTemplate"];
|
2009-02-28 21:13:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-11-23 02:16:34 +00:00
|
|
|
image = [NSImage imageNamed:@"playTemplate"];
|
2009-02-28 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self setImage:image forSegment:1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
|
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Mouse down!");
|
2009-02-28 21:13:06 +00:00
|
|
|
|
2016-06-30 05:10:29 +00:00
|
|
|
int clickedSegment = (int) [self selectedSegment];
|
2009-02-28 21:13:06 +00:00
|
|
|
if (clickedSegment == 0) //Previous
|
|
|
|
{
|
|
|
|
[playbackController prev:self];
|
|
|
|
}
|
|
|
|
else if (clickedSegment == 1) //Play
|
|
|
|
{
|
|
|
|
[playbackController playPauseResume:self];
|
|
|
|
}
|
2013-10-18 13:36:19 +00:00
|
|
|
else if (clickedSegment == 2) //Stop
|
|
|
|
{
|
|
|
|
[playbackController stop:self];
|
|
|
|
}
|
|
|
|
else if (clickedSegment == 3) //Next
|
2009-02-28 21:13:06 +00:00
|
|
|
{
|
|
|
|
[playbackController next:self];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|