From f7743b78eebd3e2fcdd3d646096f888ce9600cdb Mon Sep 17 00:00:00 2001 From: Harlan Haskins Date: Thu, 13 Feb 2014 00:38:39 -0500 Subject: [PATCH] Exposed public methods for setting the current playing item and exposed the queue (readonly) for anyone using the library to be able to get a better look at what's in there. --- GVMusicPlayerController/GVMusicPlayerController.h | 5 +++++ GVMusicPlayerController/GVMusicPlayerController.m | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/GVMusicPlayerController/GVMusicPlayerController.h b/GVMusicPlayerController/GVMusicPlayerController.h index dc49896..99d00a3 100755 --- a/GVMusicPlayerController/GVMusicPlayerController.h +++ b/GVMusicPlayerController/GVMusicPlayerController.h @@ -29,6 +29,8 @@ @property (nonatomic) float volume; // 0.0 to 1.0 @property (nonatomic, readonly) NSUInteger indexOfNowPlayingItem; // NSNotFound if no queue @property (nonatomic) BOOL updateNowPlayingCenter; // default YES +@property (nonatomic, readonly) NSArray *queue; +@property (nonatomic) BOOL shouldReturnToBeginningWhenSkippingToPreviousItem; + (GVMusicPlayerController *)sharedInstance; @@ -42,6 +44,9 @@ - (void)skipToBeginning; - (void)skipToPreviousItem; +- (void) playItemAtIndex:(NSUInteger)index; +- (void) playItem:(MPMediaItem*)item; + // Check MPMediaPlayback for other playback related methods // and properties like play, plause, currentPlaybackTime // and more. diff --git a/GVMusicPlayerController/GVMusicPlayerController.m b/GVMusicPlayerController/GVMusicPlayerController.m index 7fa2395..243ee71 100755 --- a/GVMusicPlayerController/GVMusicPlayerController.m +++ b/GVMusicPlayerController/GVMusicPlayerController.m @@ -34,7 +34,7 @@ @interface GVMusicPlayerController () @property (copy, nonatomic) NSArray *delegates; @property (strong, nonatomic) AVPlayer *player; @property (strong, nonatomic) NSArray *originalQueue; -@property (strong, nonatomic) NSArray *queue; +@property (strong, nonatomic, readwrite) NSArray *queue; @property (strong, nonatomic, readwrite) MPMediaItem *nowPlayingItem; @property (nonatomic, readwrite) NSUInteger indexOfNowPlayingItem; @property (nonatomic) BOOL interrupted; @@ -91,6 +91,7 @@ - (id)init { self.updateNowPlayingCenter = YES; self.repeatMode = MPMusicRepeatModeNone; self.shuffleMode = MPMusicShuffleModeOff; + self.shouldReturnToBeginningWhenSkippingToPreviousItem = YES; // Make sure the system follows our playback status AVAudioSession *audioSession = [AVAudioSession sharedInstance]; @@ -197,7 +198,8 @@ - (void)skipToBeginning { - (void)skipToPreviousItem { if (self.indexOfNowPlayingItem > 0) { self.indexOfNowPlayingItem--; - } else { + } + else if (self.shouldReturnToBeginningWhenSkippingToPreviousItem) { [self skipToBeginning]; } } @@ -354,6 +356,15 @@ - (void)setNowPlayingItem:(MPMediaItem *)nowPlayingItem { self.isLoadingAsset = NO; } +- (void) playItemAtIndex:(NSUInteger)index { + [self setIndexOfNowPlayingItem:index]; +} + +- (void) playItem:(MPMediaItem*)item { + NSUInteger indexOfItem = [self.queue indexOfObject:item]; + [self playItemAtIndex:indexOfItem]; +} + - (void)handleAVPlayerItemDidPlayToEndTimeNotification { if (!self.isLoadingAsset) { dispatch_async(dispatch_get_main_queue(), ^{