Skip to content

Commit

Permalink
Much more beautiful example app. Shuffle and repeat modes now work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Renskers committed Oct 4, 2012
1 parent 88c55b1 commit f30b2e6
Show file tree
Hide file tree
Showing 32 changed files with 416 additions and 95 deletions.
112 changes: 112 additions & 0 deletions Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@
0AB06DBD161DCEB500149057 /* CHANGELOG in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DB9161DCEB500149057 /* CHANGELOG */; };
0AB06DBE161DCEB500149057 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DBA161DCEB500149057 /* LICENSE */; };
0AB06DBF161DCEB500149057 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DBB161DCEB500149057 /* README.md */; };
0AB06E0E161DE30300149057 /* Controls_Pause.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DF8161DE30300149057 /* Controls_Pause.png */; };
0AB06E0F161DE30300149057 /* Controls_Pause@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DF9161DE30300149057 /* Controls_Pause@2x.png */; };
0AB06E10161DE30300149057 /* Controls_Play.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DFA161DE30300149057 /* Controls_Play.png */; };
0AB06E11161DE30300149057 /* Controls_Play@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DFB161DE30300149057 /* Controls_Play@2x.png */; };
0AB06E12161DE30300149057 /* Controls_Rewind.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DFC161DE30300149057 /* Controls_Rewind.png */; };
0AB06E13161DE30300149057 /* Controls_Rewind@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DFD161DE30300149057 /* Controls_Rewind@2x.png */; };
0AB06E14161DE30300149057 /* Controls_Rewind_Pressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DFE161DE30300149057 /* Controls_Rewind_Pressed.png */; };
0AB06E15161DE30300149057 /* Controls_Rewind_Pressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06DFF161DE30300149057 /* Controls_Rewind_Pressed@2x.png */; };
0AB06E16161DE30300149057 /* Controls_Skip.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E00161DE30300149057 /* Controls_Skip.png */; };
0AB06E17161DE30300149057 /* Controls_Skip@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E01161DE30300149057 /* Controls_Skip@2x.png */; };
0AB06E18161DE30300149057 /* Controls_Skip_Pressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E02161DE30300149057 /* Controls_Skip_Pressed.png */; };
0AB06E19161DE30300149057 /* Controls_Skip_Pressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E03161DE30300149057 /* Controls_Skip_Pressed@2x.png */; };
0AB06E1A161DE30300149057 /* Track_Repeat_Off.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E04161DE30300149057 /* Track_Repeat_Off.png */; };
0AB06E1B161DE30300149057 /* Track_Repeat_Off@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E05161DE30300149057 /* Track_Repeat_Off@2x.png */; };
0AB06E1C161DE30300149057 /* Track_Repeat_On.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E06161DE30300149057 /* Track_Repeat_On.png */; };
0AB06E1D161DE30300149057 /* Track_Repeat_On@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E07161DE30300149057 /* Track_Repeat_On@2x.png */; };
0AB06E1E161DE30300149057 /* Track_Repeat_On_Track.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E08161DE30300149057 /* Track_Repeat_On_Track.png */; };
0AB06E1F161DE30300149057 /* Track_Repeat_On_Track@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E09161DE30300149057 /* Track_Repeat_On_Track@2x.png */; };
0AB06E20161DE30300149057 /* Track_Shuffle_Off.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E0A161DE30300149057 /* Track_Shuffle_Off.png */; };
0AB06E21161DE30300149057 /* Track_Shuffle_Off@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E0B161DE30300149057 /* Track_Shuffle_Off@2x.png */; };
0AB06E22161DE30300149057 /* Track_Shuffle_On.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E0C161DE30300149057 /* Track_Shuffle_On.png */; };
0AB06E23161DE30300149057 /* Track_Shuffle_On@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E0D161DE30300149057 /* Track_Shuffle_On@2x.png */; };
0AB06E28161DE4BF00149057 /* Play_Similar_Music_Pressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E24161DE4BF00149057 /* Play_Similar_Music_Pressed.png */; };
0AB06E29161DE4BF00149057 /* Play_Similar_Music_Pressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E25161DE4BF00149057 /* Play_Similar_Music_Pressed@2x.png */; };
0AB06E2A161DE4BF00149057 /* Play_Similar_Music.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E26161DE4BF00149057 /* Play_Similar_Music.png */; };
0AB06E2B161DE4BF00149057 /* Play_Similar_Music@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AB06E27161DE4BF00149057 /* Play_Similar_Music@2x.png */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -64,6 +90,32 @@
0AB06DB9161DCEB500149057 /* CHANGELOG */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG; sourceTree = "<group>"; };
0AB06DBA161DCEB500149057 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
0AB06DBB161DCEB500149057 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
0AB06DF8161DE30300149057 /* Controls_Pause.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Controls_Pause.png; sourceTree = "<group>"; };
0AB06DF9161DE30300149057 /* Controls_Pause@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Controls_Pause@2x.png"; sourceTree = "<group>"; };
0AB06DFA161DE30300149057 /* Controls_Play.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Controls_Play.png; sourceTree = "<group>"; };
0AB06DFB161DE30300149057 /* Controls_Play@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Controls_Play@2x.png"; sourceTree = "<group>"; };
0AB06DFC161DE30300149057 /* Controls_Rewind.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Controls_Rewind.png; sourceTree = "<group>"; };
0AB06DFD161DE30300149057 /* Controls_Rewind@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Controls_Rewind@2x.png"; sourceTree = "<group>"; };
0AB06DFE161DE30300149057 /* Controls_Rewind_Pressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Controls_Rewind_Pressed.png; sourceTree = "<group>"; };
0AB06DFF161DE30300149057 /* Controls_Rewind_Pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Controls_Rewind_Pressed@2x.png"; sourceTree = "<group>"; };
0AB06E00161DE30300149057 /* Controls_Skip.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Controls_Skip.png; sourceTree = "<group>"; };
0AB06E01161DE30300149057 /* Controls_Skip@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Controls_Skip@2x.png"; sourceTree = "<group>"; };
0AB06E02161DE30300149057 /* Controls_Skip_Pressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Controls_Skip_Pressed.png; sourceTree = "<group>"; };
0AB06E03161DE30300149057 /* Controls_Skip_Pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Controls_Skip_Pressed@2x.png"; sourceTree = "<group>"; };
0AB06E04161DE30300149057 /* Track_Repeat_Off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Track_Repeat_Off.png; sourceTree = "<group>"; };
0AB06E05161DE30300149057 /* Track_Repeat_Off@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Track_Repeat_Off@2x.png"; sourceTree = "<group>"; };
0AB06E06161DE30300149057 /* Track_Repeat_On.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Track_Repeat_On.png; sourceTree = "<group>"; };
0AB06E07161DE30300149057 /* Track_Repeat_On@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Track_Repeat_On@2x.png"; sourceTree = "<group>"; };
0AB06E08161DE30300149057 /* Track_Repeat_On_Track.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Track_Repeat_On_Track.png; sourceTree = "<group>"; };
0AB06E09161DE30300149057 /* Track_Repeat_On_Track@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Track_Repeat_On_Track@2x.png"; sourceTree = "<group>"; };
0AB06E0A161DE30300149057 /* Track_Shuffle_Off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Track_Shuffle_Off.png; sourceTree = "<group>"; };
0AB06E0B161DE30300149057 /* Track_Shuffle_Off@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Track_Shuffle_Off@2x.png"; sourceTree = "<group>"; };
0AB06E0C161DE30300149057 /* Track_Shuffle_On.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Track_Shuffle_On.png; sourceTree = "<group>"; };
0AB06E0D161DE30300149057 /* Track_Shuffle_On@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Track_Shuffle_On@2x.png"; sourceTree = "<group>"; };
0AB06E24161DE4BF00149057 /* Play_Similar_Music_Pressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Play_Similar_Music_Pressed.png; sourceTree = "<group>"; };
0AB06E25161DE4BF00149057 /* Play_Similar_Music_Pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Play_Similar_Music_Pressed@2x.png"; sourceTree = "<group>"; };
0AB06E26161DE4BF00149057 /* Play_Similar_Music.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Play_Similar_Music.png; sourceTree = "<group>"; };
0AB06E27161DE4BF00149057 /* Play_Similar_Music@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Play_Similar_Music@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -131,6 +183,7 @@
0A7E5EC8161C9DB0006AB45D /* ViewController.m */,
0A7E5F40161DB640006AB45D /* NSString+TimeToString.h */,
0A7E5F41161DB640006AB45D /* NSString+TimeToString.m */,
0AB06DF7161DE30300149057 /* images */,
0A7E5EB3161C9DB0006AB45D /* Supporting Files */,
);
path = Example;
Expand Down Expand Up @@ -161,6 +214,39 @@
path = GVMusicPlayerController;
sourceTree = "<group>";
};
0AB06DF7161DE30300149057 /* images */ = {
isa = PBXGroup;
children = (
0AB06E24161DE4BF00149057 /* Play_Similar_Music_Pressed.png */,
0AB06E25161DE4BF00149057 /* Play_Similar_Music_Pressed@2x.png */,
0AB06E26161DE4BF00149057 /* Play_Similar_Music.png */,
0AB06E27161DE4BF00149057 /* Play_Similar_Music@2x.png */,
0AB06DF8161DE30300149057 /* Controls_Pause.png */,
0AB06DF9161DE30300149057 /* Controls_Pause@2x.png */,
0AB06DFA161DE30300149057 /* Controls_Play.png */,
0AB06DFB161DE30300149057 /* Controls_Play@2x.png */,
0AB06DFC161DE30300149057 /* Controls_Rewind.png */,
0AB06DFD161DE30300149057 /* Controls_Rewind@2x.png */,
0AB06DFE161DE30300149057 /* Controls_Rewind_Pressed.png */,
0AB06DFF161DE30300149057 /* Controls_Rewind_Pressed@2x.png */,
0AB06E00161DE30300149057 /* Controls_Skip.png */,
0AB06E01161DE30300149057 /* Controls_Skip@2x.png */,
0AB06E02161DE30300149057 /* Controls_Skip_Pressed.png */,
0AB06E03161DE30300149057 /* Controls_Skip_Pressed@2x.png */,
0AB06E04161DE30300149057 /* Track_Repeat_Off.png */,
0AB06E05161DE30300149057 /* Track_Repeat_Off@2x.png */,
0AB06E06161DE30300149057 /* Track_Repeat_On.png */,
0AB06E07161DE30300149057 /* Track_Repeat_On@2x.png */,
0AB06E08161DE30300149057 /* Track_Repeat_On_Track.png */,
0AB06E09161DE30300149057 /* Track_Repeat_On_Track@2x.png */,
0AB06E0A161DE30300149057 /* Track_Shuffle_Off.png */,
0AB06E0B161DE30300149057 /* Track_Shuffle_Off@2x.png */,
0AB06E0C161DE30300149057 /* Track_Shuffle_On.png */,
0AB06E0D161DE30300149057 /* Track_Shuffle_On@2x.png */,
);
path = images;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -223,6 +309,32 @@
0AB06DBD161DCEB500149057 /* CHANGELOG in Resources */,
0AB06DBE161DCEB500149057 /* LICENSE in Resources */,
0AB06DBF161DCEB500149057 /* README.md in Resources */,
0AB06E0E161DE30300149057 /* Controls_Pause.png in Resources */,
0AB06E0F161DE30300149057 /* Controls_Pause@2x.png in Resources */,
0AB06E10161DE30300149057 /* Controls_Play.png in Resources */,
0AB06E11161DE30300149057 /* Controls_Play@2x.png in Resources */,
0AB06E12161DE30300149057 /* Controls_Rewind.png in Resources */,
0AB06E13161DE30300149057 /* Controls_Rewind@2x.png in Resources */,
0AB06E14161DE30300149057 /* Controls_Rewind_Pressed.png in Resources */,
0AB06E15161DE30300149057 /* Controls_Rewind_Pressed@2x.png in Resources */,
0AB06E16161DE30300149057 /* Controls_Skip.png in Resources */,
0AB06E17161DE30300149057 /* Controls_Skip@2x.png in Resources */,
0AB06E18161DE30300149057 /* Controls_Skip_Pressed.png in Resources */,
0AB06E19161DE30300149057 /* Controls_Skip_Pressed@2x.png in Resources */,
0AB06E1A161DE30300149057 /* Track_Repeat_Off.png in Resources */,
0AB06E1B161DE30300149057 /* Track_Repeat_Off@2x.png in Resources */,
0AB06E1C161DE30300149057 /* Track_Repeat_On.png in Resources */,
0AB06E1D161DE30300149057 /* Track_Repeat_On@2x.png in Resources */,
0AB06E1E161DE30300149057 /* Track_Repeat_On_Track.png in Resources */,
0AB06E1F161DE30300149057 /* Track_Repeat_On_Track@2x.png in Resources */,
0AB06E20161DE30300149057 /* Track_Shuffle_Off.png in Resources */,
0AB06E21161DE30300149057 /* Track_Shuffle_Off@2x.png in Resources */,
0AB06E22161DE30300149057 /* Track_Shuffle_On.png in Resources */,
0AB06E23161DE30300149057 /* Track_Shuffle_On@2x.png in Resources */,
0AB06E28161DE4BF00149057 /* Play_Similar_Music_Pressed.png in Resources */,
0AB06E29161DE4BF00149057 /* Play_Similar_Music_Pressed@2x.png in Resources */,
0AB06E2A161DE4BF00149057 /* Play_Similar_Music.png in Resources */,
0AB06E2B161DE4BF00149057 /* Play_Similar_Music@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
66 changes: 66 additions & 0 deletions Example/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ @interface ViewController () <GVMusicPlayerControllerDelegate, MPMediaPickerCont
@property (weak, nonatomic) IBOutlet UILabel *trackCurrentPlaybackTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *trackLengthLabel;
@property (weak, nonatomic) IBOutlet UIView *chooseView;
@property (weak, nonatomic) IBOutlet UIButton *repeatButton;
@property (weak, nonatomic) IBOutlet UIButton *shuffleButton;
@property (strong, nonatomic) NSTimer *timer;
@property BOOL panningProgress;
@property BOOL panningVolume;
Expand Down Expand Up @@ -58,6 +60,8 @@ - (void)timedJob {

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.shuffleButton.selected = ([GVMusicPlayerController sharedInstance].shuffleMode != MPMusicShuffleModeOff);
[self setCorrectRepeatButtomImage];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
Expand Down Expand Up @@ -123,6 +127,65 @@ - (IBAction)progressEnd {
self.panningProgress = NO;
}

- (IBAction)shuffleButtonPressed {
self.shuffleButton.selected = !self.shuffleButton.selected;

if (self.shuffleButton.selected) {
[GVMusicPlayerController sharedInstance].shuffleMode = MPMusicShuffleModeSongs;
} else {
[GVMusicPlayerController sharedInstance].shuffleMode = MPMusicShuffleModeOff;
}
}

- (IBAction)repeatButtonPressed {
switch ([GVMusicPlayerController sharedInstance].repeatMode) {
case MPMusicRepeatModeAll:
// From all to one
[GVMusicPlayerController sharedInstance].repeatMode = MPMusicRepeatModeOne;
break;

case MPMusicRepeatModeOne:
// From one to none
[GVMusicPlayerController sharedInstance].repeatMode = MPMusicRepeatModeNone;
break;

case MPMusicRepeatModeNone:
// From none to all
[GVMusicPlayerController sharedInstance].repeatMode = MPMusicRepeatModeAll;
break;

default:
[GVMusicPlayerController sharedInstance].repeatMode = MPMusicRepeatModeAll;
break;
}

[self setCorrectRepeatButtomImage];
}

- (void)setCorrectRepeatButtomImage {
NSString *imageName;

switch ([GVMusicPlayerController sharedInstance].repeatMode) {
case MPMusicRepeatModeAll:
imageName = @"Track_Repeat_On";
break;

case MPMusicRepeatModeOne:
imageName = @"Track_Repeat_On_Track";
break;

case MPMusicRepeatModeNone:
imageName = @"Track_Repeat_Off";
break;

default:
imageName = @"Track_Repeat_Off";
break;
}

[self.repeatButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
}

#pragma mark - AVMusicPlayerControllerDelegate

- (void)musicPlayer:(GVMusicPlayerController *)musicPlayer playbackStateChanged:(MPMusicPlaybackState)playbackState previousPlaybackState:(MPMusicPlaybackState)previousPlaybackState {
Expand Down Expand Up @@ -152,6 +215,8 @@ - (void)musicPlayer:(GVMusicPlayerController *)musicPlayer trackDidChange:(MPMed
if (artwork != nil) {
self.imageView.image = [artwork imageWithSize:self.imageView.frame.size];
}

NSLog(@"Proof that this code is being called, even in the background!");
}

- (void)musicPlayer:(GVMusicPlayerController *)musicPlayer volumeChanged:(float)volume {
Expand All @@ -168,6 +233,7 @@ - (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
[[GVMusicPlayerController sharedInstance] setQueueWithItemCollection:mediaItemCollection];
[[GVMusicPlayerController sharedInstance] play];
[mediaPicker dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
Loading

0 comments on commit f30b2e6

Please sign in to comment.