Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finished Spotify player

(Done first revision of the Spotify content source)
  • Loading branch information...
commit 3b4be35fed9ae223451d877361fb106aa4641c9c 1 parent ec8bc3a
@indragiek authored
View
2  Audio Players/SMKAVQueuePlayer.m
@@ -35,6 +35,7 @@ - (id)init
SMKAVQueuePlayer *strongSelf = weakSelf;
strongSelf.playbackTime = (NSTimeInterval)CMTimeGetSeconds(time);
}];
+ self.seekTimeInterval = SMKPlayerDefaultSeekTimeInterval;
}
return self;
}
@@ -170,6 +171,7 @@ - (void)_itemDidFailToPlayToEndTime:(NSNotification *)notification
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
if (object == self && [keyPath isEqualToString:@"rate"]) {
float newValue = [[change valueForKey:NSKeyValueChangeNewKey] floatValue];
[self willChangeValueForKey:@"playing"];
View
1  Audio Players/SMKSFBAudioPlayer.mm
@@ -107,6 +107,7 @@ - (id)init
AudioDecoder::SetAutomaticallyOpenDecoders(true);
_renderTimer = [NSTimer timerWithTimeInterval:1.f target:self selector:@selector(_renderTimerFired:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:_renderTimer forMode:NSRunLoopCommonModes];
+ self.seekTimeInterval = SMKPlayerDefaultSeekTimeInterval;
}
return self;
}
View
19 Audio Players/SMKSpotifyPlayer.h
@@ -0,0 +1,19 @@
+//
+// SMKSpotifyPlayer.h
+// SNRMusicKit
+//
+// Created by Indragie Karunaratne on 2012-08-25.
+// Copyright (c) 2012 Indragie Karunaratne. All rights reserved.
+//
+
+#import <CocoaLibSpotify/CocoaLibSpotify.h>
+#import "SMKPlayer.h"
+
+@interface SMKSpotifyPlayer : SPPlaybackManager <SMKPlayer>
+
+#pragma mark - SMKPlayer
+@property (nonatomic, copy) void (^finishedTrackBlock)(id<SMKPlayer> player, id<SMKTrack> track, NSError *error);
+@property (nonatomic, assign) NSTimeInterval seekTimeInterval;
+@property (nonatomic, assign, readonly) NSTimeInterval playbackTime;
+@property (nonatomic, assign, readonly) BOOL playing;
+@end
View
116 Audio Players/SMKSpotifyPlayer.m
@@ -0,0 +1,116 @@
+//
+// SMKSpotifyPlayer.m
+// SNRMusicKit
+//
+// Created by Indragie Karunaratne on 2012-08-25.
+// Copyright (c) 2012 Indragie Karunaratne. All rights reserved.
+//
+
+#import "SMKSpotifyPlayer.h"
+#import "SMKSpotifyContentSource.h"
+#import "SPTrack+SMKTrack.h"
+
+@implementation SMKSpotifyPlayer {
+ id<SMKTrack> _oldCurrentTrack;
+}
+
+- (id)initWithPlaybackSession:(SPSession *)aSession
+{
+ if ((self = [super initWithPlaybackSession:aSession])) {
+ self.seekTimeInterval = SMKPlayerDefaultSeekTimeInterval;
+ [self addObserver:self forKeyPath:@"playbackSession.playing" options:NSKeyValueObservingOptionNew context:NULL];
+ [self addObserver:self forKeyPath:@"trackPosition" options:NSKeyValueObservingOptionNew context:NULL];
+ [self addObserver:self forKeyPath:@"currentTrack" options:NSKeyValueObservingOptionNew context:NULL];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [self removeObserver:self forKeyPath:@"playbackSession.playing"];
+ [self removeObserver:self forKeyPath:@"trackPosition"];
+ [self removeObserver:self forKeyPath:@"currentTrack"];
+}
+
+#pragma mark - KVO
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ id newValue = [change valueForKey:NSKeyValueChangeNewKey];
+ if ([keyPath isEqualToString:@"playbackSession.playing"] && object == self) {
+ [self willChangeValueForKey:@"playing"];
+ _playing = [newValue boolValue];
+ [self didChangeValueForKey:@"playing"];
+ } else if ([keyPath isEqualToString:@"trackPosition"] && object == self) {
+ [self willChangeValueForKey:@"playbackTime"];
+ _playbackTime = [newValue doubleValue];
+ } else if ([keyPath isEqualToString:@"currentTrack"]) {
+ if (!newValue) {
+ if (self.finishedTrackBlock)
+ self.finishedTrackBlock(self, _oldCurrentTrack, nil);
+ _oldCurrentTrack = nil;
+ }
+ }
+}
+
+#pragma mark - SMKPlayer
+
++ (NSSet *)supportedContentSourceClasses
+{
+ return [NSSet setWithObject:NSStringFromClass([SMKSpotifyContentSource class])];
+}
+
++ (BOOL)supportsPreloading
+{
+ return NO;
+}
+
++ (BOOL)supportsAirPlay
+{
+ return NO;
+}
+
+- (BOOL)supportsSeeking
+{
+ return YES;
+}
+
+- (void)pause
+{
+ [self setIsPlaying:NO];
+}
+
+- (void)play
+{
+ [self setIsPlaying:YES];
+}
+
+- (void)seekToPlaybackTime:(NSTimeInterval)time
+{
+ [self seekToTrackPosition:time];
+}
+
+- (void)seekBackward
+{
+ NSTimeInterval newTime = [self trackPosition] - self.seekTimeInterval;
+ [self seekToTrackPosition:newTime];
+}
+
+- (void)seekForward
+{
+ NSTimeInterval newTime = [self trackPosition] + self.seekTimeInterval;
+ [self seekToTrackPosition:newTime];
+}
+
+- (void)playTrack:(SPTrack *)aTrack callback:(SPErrorableOperationCallback)block
+{
+ [super playTrack:aTrack callback:block];
+ _oldCurrentTrack = aTrack;
+}
+
+- (void)playTrack:(id<SMKTrack>)track completionHandler:(void (^)(NSError *))handler
+{
+ [self playTrack:(SPTrack *)track callback:handler];
+}
+@end
View
9 Common Headers/SMKGlobalConstants.h
@@ -0,0 +1,9 @@
+//
+// SMKGlobalConstants.h
+// SNRMusicKit
+//
+// Created by Indragie Karunaratne on 2012-08-25.
+// Copyright (c) 2012 Indragie Karunaratne. All rights reserved.
+//
+
+extern NSTimeInterval const SMKPlayerDefaultSeekTimeInterval;
View
11 Common Headers/SMKGlobalConstants.m
@@ -0,0 +1,11 @@
+//
+// SMKGlobalConstants.m
+// SNRMusicKit
+//
+// Created by Indragie Karunaratne on 2012-08-25.
+// Copyright (c) 2012 Indragie Karunaratne. All rights reserved.
+//
+
+#import "SMKGlobalConstants.h"
+
+NSTimeInterval const SMKPlayerDefaultSeekTimeInterval = 3.0;
View
5 Content Sources/Spotify/SMKSpotifyContentSource.m
@@ -7,9 +7,11 @@
//
#import "SMKSpotifyContentSource.h"
+#import "SMKSpotifyConstants.h"
+#import "SMKSpotifyPlayer.h"
+
#import "NSObject+SMKSpotifyAdditions.h"
#import "NSMutableArray+SMKAdditions.h"
-#import "SMKSpotifyConstants.h"
@implementation SMKSpotifyContentSource {
dispatch_queue_t _localQueue;
@@ -18,6 +20,7 @@ @implementation SMKSpotifyContentSource {
- (NSString *)name { return @"Spotify"; }
+ (BOOL)supportsBatching { return NO; }
++ (Class)defaultPlayerClass { return [SMKSpotifyPlayer class]; }
- (NSArray *)playlistsWithSortDescriptors:(NSArray *)sortDescriptors
batchSize:(NSUInteger)batchSize
View
4 README.md
@@ -44,7 +44,7 @@ git submodule update
<td>MPMediaLibrary</td><td>✔</td><td>✘</td><td>✘</td>
</tr>
<tr>
- <td>Spotify</td><td>✔</td><td>✔</td><td></td>
+ <td>Spotify</td><td>✔</td><td>✔</td><td></td>
</tr>
<tr>
<td>Rdio</td><td>✔</td><td>✘</td><td>✘</td>
@@ -70,7 +70,7 @@ git submodule update
<td>MPMusicPlayerController</td><td>✔</td><td>✘</td><td>✘</td>
</tr>
<tr>
- <td>Spotify SDK^2</td><td>✔</td><td>✔</td><td></td>
+ <td>Spotify SDK^2</td><td>✔</td><td>✔</td><td></td>
</tr>
<tr>
<td>Rdio SDK^2</td><td>✔</td><td>✘</td><td>✘</td>
View
20 SNRMusicKit.xcodeproj/project.pbxproj
@@ -26,6 +26,12 @@
0335CC3215E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 0335CC3015E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.h */; };
0335CC3315E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0335CC3115E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m */; };
0335CC3415E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0335CC3115E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m */; };
+ 03576BAE15E95C1B00316930 /* SMKSpotifyPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 03576BAC15E95C1B00316930 /* SMKSpotifyPlayer.h */; };
+ 03576BAF15E95C1B00316930 /* SMKSpotifyPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 03576BAD15E95C1B00316930 /* SMKSpotifyPlayer.m */; };
+ 03576BB015E95C1B00316930 /* SMKSpotifyPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 03576BAD15E95C1B00316930 /* SMKSpotifyPlayer.m */; };
+ 03576BB315E961A000316930 /* SMKGlobalConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 03576BB115E961A000316930 /* SMKGlobalConstants.h */; };
+ 03576BB415E961A000316930 /* SMKGlobalConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 03576BB215E961A000316930 /* SMKGlobalConstants.m */; };
+ 03576BB515E961A000316930 /* SMKGlobalConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 03576BB215E961A000316930 /* SMKGlobalConstants.m */; };
0369921815E3EB0B003BCCBE /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 036991F215E3EAE1003BCCBE /* Cocoa.framework */; };
0369921E15E3EB0B003BCCBE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0369921C15E3EB0B003BCCBE /* InfoPlist.strings */; };
0369922215E3EB0B003BCCBE /* SNRMusicKitMac.m in Sources */ = {isa = PBXBuildFile; fileRef = 0369922115E3EB0B003BCCBE /* SNRMusicKitMac.m */; };
@@ -352,6 +358,10 @@
030CE8D515E5CE0000AC12BE /* SMKConvenience.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SMKConvenience.h; path = "Common Headers/SMKConvenience.h"; sourceTree = "<group>"; };
0335CC3015E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSMutableArray+SMKAdditions.h"; path = "Categories/NSMutableArray+SMKAdditions.h"; sourceTree = "<group>"; };
0335CC3115E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSMutableArray+SMKAdditions.m"; path = "Categories/NSMutableArray+SMKAdditions.m"; sourceTree = "<group>"; };
+ 03576BAC15E95C1B00316930 /* SMKSpotifyPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SMKSpotifyPlayer.h; path = "Audio Players/SMKSpotifyPlayer.h"; sourceTree = "<group>"; };
+ 03576BAD15E95C1B00316930 /* SMKSpotifyPlayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SMKSpotifyPlayer.m; path = "Audio Players/SMKSpotifyPlayer.m"; sourceTree = "<group>"; };
+ 03576BB115E961A000316930 /* SMKGlobalConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SMKGlobalConstants.h; path = "Common Headers/SMKGlobalConstants.h"; sourceTree = "<group>"; };
+ 03576BB215E961A000316930 /* SMKGlobalConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SMKGlobalConstants.m; path = "Common Headers/SMKGlobalConstants.m"; sourceTree = "<group>"; };
036991F215E3EAE1003BCCBE /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
036991F515E3EAE1003BCCBE /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
036991F615E3EAE1003BCCBE /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
@@ -886,6 +896,8 @@
03FBEC9E15E6E0C100A67DEE /* SMKAVQueuePlayer.m */,
03FBECA215E6E2EB00A67DEE /* SMKAVPlayerItem.h */,
03FBECA315E6E2EB00A67DEE /* SMKAVPlayerItem.m */,
+ 03576BAC15E95C1B00316930 /* SMKSpotifyPlayer.h */,
+ 03576BAD15E95C1B00316930 /* SMKSpotifyPlayer.m */,
);
name = "Audio Players";
sourceTree = "<group>";
@@ -897,6 +909,8 @@
03F795C115E47A3C00C9F652 /* SMKErrorCodes.h */,
03F795C915E47BC400C9F652 /* SMKErrorCodes.m */,
03EB018D15E86728001F3A02 /* SMKPlatformImports.h */,
+ 03576BB115E961A000316930 /* SMKGlobalConstants.h */,
+ 03576BB215E961A000316930 /* SMKGlobalConstants.m */,
);
name = "Common Headers";
sourceTree = "<group>";
@@ -1108,6 +1122,8 @@
03EB019B15E88746001F3A02 /* SPAlbum+SMKAlbum.h in Headers */,
03EB01A015E88F17001F3A02 /* SPArtist+SMKArtist.h in Headers */,
0335CC3215E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.h in Headers */,
+ 03576BAE15E95C1B00316930 /* SMKSpotifyPlayer.h in Headers */,
+ 03576BB315E961A000316930 /* SMKGlobalConstants.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1400,6 +1416,8 @@
03EB019C15E88746001F3A02 /* SPAlbum+SMKAlbum.m in Sources */,
03EB01A115E88F17001F3A02 /* SPArtist+SMKArtist.m in Sources */,
0335CC3315E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m in Sources */,
+ 03576BAF15E95C1B00316930 /* SMKSpotifyPlayer.m in Sources */,
+ 03576BB415E961A000316930 /* SMKGlobalConstants.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1444,6 +1462,8 @@
03EB019D15E88746001F3A02 /* SPAlbum+SMKAlbum.m in Sources */,
03EB01A215E88F17001F3A02 /* SPArtist+SMKArtist.m in Sources */,
0335CC3415E8AA6400E4F9DF /* NSMutableArray+SMKAdditions.m in Sources */,
+ 03576BB015E95C1B00316930 /* SMKSpotifyPlayer.m in Sources */,
+ 03576BB515E961A000316930 /* SMKGlobalConstants.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  SNRMusicKit.xcodeproj/project.xcworkspace/xcuserdata/indragie.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
1  SNRMusicKitMac/SNRMusicKitMac-Prefix.pch
@@ -7,4 +7,5 @@
#import "SMKErrorCodes.h"
#import "SMKConvenience.h"
#import "SMKPlatformImports.h"
+ #import "SMKGlobalConstants.h"
#endif
View
7 SNRMusicKitiOS/SNRMusicKitiOS-Prefix.pch
@@ -4,7 +4,8 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
-#import "SMKErrorCodes.h"
-#import "SMKConvenience.h"
-#import "SMKPlatformImports.h"
+ #import "SMKErrorCodes.h"
+ #import "SMKConvenience.h"
+ #import "SMKPlatformImports.h"
+ #import "SMKGlobalConstants.h"
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.