Fixed playback buttons on mini mode. Play now turns to pause.

CQTexperiment
vspader 2009-02-28 13:13:06 -08:00
parent 606cdef1d0
commit fd4fa4c62d
6 changed files with 158 additions and 71 deletions

View File

@ -21,8 +21,6 @@
IBOutlet NSSlider *volumeSlider;
IBOutlet NSSegmentedControl *playbackButtons;
IBOutlet NSArrayController *outputDevices;
NSTimer *positionTimer;
@ -33,8 +31,6 @@
double position;
BOOL seekable;
BOOL showTimeRemaining;
AudioScrobbler *scrobbler;
}
@ -49,7 +45,6 @@
- (IBAction)pauseResume:(id)sender;
- (IBAction)skipToNextAlbum:(id)sender;
- (IBAction)skipToPreviousAlbum:(id)sender;
- (IBAction)playbackButtonClick:(id)sender;
- (IBAction)play:(id)sender;
- (IBAction)pause:(id)sender;

View File

@ -27,9 +27,7 @@
audioPlayer = [[AudioPlayer alloc] init];
[audioPlayer setDelegate:self];
playbackStatus = kCogStatusStopped;
showTimeRemaining = NO;
[self setPlaybackStatus: kCogStatusStopped];
scrobbler = [[AudioScrobbler alloc] init];
[GrowlApplicationBridge setGrowlDelegate:self];
@ -94,7 +92,7 @@
- (IBAction)pause:(id)sender
{
[audioPlayer pause];
playbackStatus = kCogStatusPaused;
[self setPlaybackStatus: kCogStatusPaused];
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
[scrobbler pause];
@ -130,24 +128,6 @@
}
- (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];
}
}
- (IBAction)play:(id)sender
{
if ([playlistView selectedRow] == -1)
@ -252,7 +232,8 @@
[self setPosition:seekTo];
}
- (void)changePlayButtonImage:(NSString *)name
/*
- (void)changePlayButtonImage:(NSString *)name
{
NSImage *img = [NSImage imageNamed:name];
// [img retain];
@ -264,7 +245,7 @@
[playbackButtons setImage:img forSegment:1];
}
*/
- (IBAction)changeVolume:(id)sender
{
NSLog(@"VOLUME: %lf, %lf", [sender doubleValue], linearToLogarithmic([sender doubleValue]));
@ -295,7 +276,7 @@
[audioPlayer setVolume:originalVolume];
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume)];
[audioTimer invalidate];
playbackStatus = kCogStatusPaused;
[self setPlaybackStatus: kCogStatusPaused];
}
}
@ -319,7 +300,7 @@
{
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume)];
[audioTimer invalidate];
playbackStatus = kCogStatusPlaying;
[self setPlaybackStatus: kCogStatusPlaying];
}
}
@ -355,7 +336,7 @@
[self pauseResume:self];
}
playbackStatus = kCogStatusFading;
[self setPlaybackStatus: kCogStatusFading];
}
@ -521,9 +502,6 @@
[self setPosition:0];
[self setSeekable:NO]; // the player stopped, disable the slider
}
//Show play image
[self changePlayButtonImage:@"play"];
}
else if (status == kCogStatusPlaying)
{
@ -531,9 +509,6 @@
positionTimer = [NSTimer timerWithTimeInterval:1.00 target:self selector:@selector(updatePosition:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:positionTimer forMode:NSRunLoopCommonModes];
}
//Show pause
[self changePlayButtonImage:@"pause"];
}
if (status == kCogStatusStopped) {
@ -546,7 +521,7 @@
[self setSeekable:YES];
}
playbackStatus = status;
[self setPlaybackStatus:status];
}
- (void)playlistDidChange:(PlaylistController *)p

View File

@ -28,6 +28,7 @@
1738589B0E0D92DD00488CD4 /* SideBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173858950E0D92DD00488CD4 /* SideBarController.m */; };
1738589D0E0D92DD00488CD4 /* SideWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173858990E0D92DD00488CD4 /* SideWindowController.m */; };
173A43A10F3FD26500676A7B /* ToolTipWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 173A43A00F3FD26500676A7B /* ToolTipWindow.m */; };
1752C36C0F59E00100F85F28 /* PlaybackButtons.m in Sources */ = {isa = PBXBuildFile; fileRef = 1752C36B0F59E00100F85F28 /* PlaybackButtons.m */; };
1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 1755E1F70BA0D2B600CA3560 /* PlaylistLoader.m */; };
1766C6930B911DF1004A7AE4 /* AudioScrobbler.m in Sources */ = {isa = PBXBuildFile; fileRef = 1766C68F0B911DF1004A7AE4 /* AudioScrobbler.m */; };
1766C6950B911DF1004A7AE4 /* AudioScrobblerClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 1766C6910B911DF1004A7AE4 /* AudioScrobblerClient.m */; };
@ -537,6 +538,8 @@
173858990E0D92DD00488CD4 /* SideWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SideWindowController.m; path = SideView/SideWindowController.m; sourceTree = "<group>"; };
173A439F0F3FD26500676A7B /* ToolTipWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToolTipWindow.h; path = ToolTip/ToolTipWindow.h; sourceTree = "<group>"; };
173A43A00F3FD26500676A7B /* ToolTipWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ToolTipWindow.m; path = ToolTip/ToolTipWindow.m; sourceTree = "<group>"; };
1752C36A0F59E00100F85F28 /* PlaybackButtons.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlaybackButtons.h; path = Window/PlaybackButtons.h; sourceTree = "<group>"; };
1752C36B0F59E00100F85F28 /* PlaybackButtons.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PlaybackButtons.m; path = Window/PlaybackButtons.m; sourceTree = "<group>"; };
1755E1F60BA0D2B600CA3560 /* PlaylistLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PlaylistLoader.h; sourceTree = "<group>"; };
1755E1F70BA0D2B600CA3560 /* PlaylistLoader.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = PlaylistLoader.m; sourceTree = "<group>"; };
1766C68E0B911DF1004A7AE4 /* AudioScrobbler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AudioScrobbler.h; sourceTree = "<group>"; };
@ -1133,6 +1136,8 @@
17E0D5D20F520E75005B6FED /* Window */ = {
isa = PBXGroup;
children = (
1752C36A0F59E00100F85F28 /* PlaybackButtons.h */,
1752C36B0F59E00100F85F28 /* PlaybackButtons.m */,
172A123A0F5912AE0078EF0C /* ShuffleTransformers.h */,
172A123B0F5912AE0078EF0C /* ShuffleTransformers.m */,
172A12310F5911D20078EF0C /* RepeatTransformers.h */,
@ -1848,6 +1853,7 @@
172A12330F5911D20078EF0C /* RepeatTransformers.m in Sources */,
172A123C0F5912AE0078EF0C /* ShuffleTransformers.m in Sources */,
172A12A90F59AF8A0078EF0C /* NSString+CogSort.m in Sources */,
1752C36C0F59E00100F85F28 /* PlaybackButtons.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -8,9 +8,9 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="29"/>
<integer value="2234"/>
<integer value="21"/>
<integer value="29"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -5046,22 +5046,6 @@ OQA</bytes>
</object>
<int key="connectionID">1597</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">playbackButtons</string>
<reference key="source" ref="936098491"/>
<reference key="destination" ref="40234197"/>
</object>
<int key="connectionID">1603</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">playbackButtonClick:</string>
<reference key="source" ref="936098491"/>
<reference key="destination" ref="40234197"/>
</object>
<int key="connectionID">1604</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">changeVolume:</string>
@ -6784,14 +6768,6 @@ OQA</bytes>
</object>
<int key="connectionID">2388</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">playbackButtonClick:</string>
<reference key="source" ref="936098491"/>
<reference key="destination" ref="554424892"/>
</object>
<int key="connectionID">2389</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">image: shuffle</string>
@ -6876,6 +6852,22 @@ OQA</bytes>
</object>
<int key="connectionID">2400</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">playbackController</string>
<reference key="source" ref="40234197"/>
<reference key="destination" ref="936098491"/>
</object>
<int key="connectionID">2401</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">playbackController</string>
<reference key="source" ref="554424892"/>
<reference key="destination" ref="936098491"/>
</object>
<int key="connectionID">2402</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -9375,6 +9367,7 @@ OQA</bytes>
<string>1532.ImportedFromIB2</string>
<string>1533.IBPluginDependency</string>
<string>1533.ImportedFromIB2</string>
<string>1537.CustomClassName</string>
<string>1537.IBPluginDependency</string>
<string>1537.ImportedFromIB2</string>
<string>1538.IBPluginDependency</string>
@ -9637,6 +9630,7 @@ OQA</bytes>
<string>2294.CustomClassName</string>
<string>2294.IBPluginDependency</string>
<string>2294.ImportedFromIB2</string>
<string>2295.CustomClassName</string>
<string>2295.IBPluginDependency</string>
<string>2295.ImportedFromIB2</string>
<string>2296.IBPluginDependency</string>
@ -9994,6 +9988,7 @@ OQA</bytes>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>PlaybackButtons</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@ -10256,6 +10251,7 @@ OQA</bytes>
<string>TrackingCell</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>PlaybackButtons</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@ -10451,7 +10447,7 @@ OQA</bytes>
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">2400</int>
<int key="maxID">2402</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -10747,6 +10743,18 @@ OQA</bytes>
<string key="minorKey">FileTree/PathWatcher.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">PlaybackButtons</string>
<string key="superclassName">NSSegmentedControl</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">playbackController</string>
<string key="NS.object.0">PlaybackController</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">Window/PlaybackButtons.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">PlaybackController</string>
<string key="superclassName">NSObject</string>
@ -10763,14 +10771,12 @@ OQA</bytes>
<string>pauseResume:</string>
<string>play:</string>
<string>playPauseResume:</string>
<string>playbackButtonClick:</string>
<string>prev:</string>
<string>resume:</string>
<string>seek:</string>
<string>skipToNextAlbum:</string>
<string>skipToPreviousAlbum:</string>
<string>stop:</string>
<string>toggleShowTimeRemaining:</string>
<string>volumeDown:</string>
<string>volumeUp:</string>
</object>
@ -10793,8 +10799,6 @@ OQA</bytes>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
@ -10802,7 +10806,6 @@ OQA</bytes>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>outputDevices</string>
<string>playbackButtons</string>
<string>playlistController</string>
<string>playlistView</string>
<string>volumeSlider</string>
@ -10810,7 +10813,6 @@ OQA</bytes>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSArrayController</string>
<string>NSSegmentedControl</string>
<string>PlaylistController</string>
<string>PlaylistView</string>
<string>NSSlider</string>

20
Window/PlaybackButtons.h Normal file
View File

@ -0,0 +1,20 @@
//
// PlaybackButtons.h
// Cog
//
// Created by Vincent Spader on 2/28/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@class PlaybackController;
@interface PlaybackButtons : NSSegmentedControl {
IBOutlet PlaybackController *playbackController;
}
- (void)startObserving;
- (void)stopObserving;
@end

89
Window/PlaybackButtons.m Normal file
View File

@ -0,0 +1,89 @@
//
// 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>
@implementation PlaybackButtons
static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackButtonsPlaybackStatusObservationContext";
- (void)dealloc
{
[self stopObserving];
[super dealloc];
}
- (void)awakeFromNib
{
[self startObserving];
}
- (void)startObserving
{
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:PlaybackButtonsPlaybackStatusObservationContext];
}
- (void)stopObserving
{
[playbackController removeObserver:self forKeyPath:@"playbackStatus"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([PlaybackButtonsPlaybackStatusObservationContext isEqual:context])
{
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
NSImage *image = nil;
if (playbackStatus == kCogStatusPlaying || playbackStatus == kCogStatusFading) {
image = [NSImage imageNamed:@"pause"];
}
else {
image = [NSImage imageNamed:@"play"];
}
[self setImage:image forSegment:1];
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
{
NSLog(@"Mouse down!");
int clickedSegment = [self selectedSegment];
if (clickedSegment == 0) //Previous
{
[playbackController prev:self];
}
else if (clickedSegment == 1) //Play
{
[playbackController playPauseResume:self];
}
else if (clickedSegment == 2) //Next
{
[playbackController next:self];
}
else {
return NO;
}
return YES;
}
@end