Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed public methods for setting the current playing item and exposed ... #10

Merged
merged 1 commit into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Exposed public methods for setting the current playing item and expos…
…ed the queue (readonly) for anyone using the library to be able to get a better look at what's in there.
  • Loading branch information
Harlan Haskins committed Feb 13, 2014
commit f7743b78eebd3e2fcdd3d646096f888ce9600cdb
5 changes: 5 additions & 0 deletions GVMusicPlayerController/GVMusicPlayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions GVMusicPlayerController/GVMusicPlayerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ @interface GVMusicPlayerController () <AVAudioSessionDelegate>
@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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -197,7 +198,8 @@ - (void)skipToBeginning {
- (void)skipToPreviousItem {
if (self.indexOfNowPlayingItem > 0) {
self.indexOfNowPlayingItem--;
} else {
}
else if (self.shouldReturnToBeginningWhenSkippingToPreviousItem) {
[self skipToBeginning];
}
}
Expand Down Expand Up @@ -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(), ^{
Expand Down