Merge lp:~rockstar/ubuntuone-ios-music/remote-controls into lp:ubuntuone-ios-music

Proposed by Paul Hummer
Status: Merged
Approved by: Paul Hummer
Approved revision: 261
Merged at revision: 253
Proposed branch: lp:~rockstar/ubuntuone-ios-music/remote-controls
Merge into: lp:ubuntuone-ios-music
Prerequisite: lp:~rockstar/ubuntuone-ios-music/remove-audiostreamer
Diff against target: 75 lines (+38/-2)
2 files modified
Music/UOAppDelegate.m (+31/-2)
Music/Utilities/UOPlayer.m (+7/-0)
To merge this branch: bzr merge lp:~rockstar/ubuntuone-ios-music/remote-controls
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Review via email: mp+148278@code.launchpad.net

Commit message

Enable remote control events

Description of the change

This branch enables the remote control events.

It looks like a small branch, but I was pulling my hair out trying to figure it out, and read every Audio document Apple publishes. Turns out that the simulator just doesn't send remote control events, ever (despite Apple saying the double Home click controls do). Once I tried it on my device, everything worked fine.

While here, I also took the time to set the MPNowPlayingInfo so that the information is sent to Apple TV or displayed on your lock screen (complete with Album Art), which was a requested feature by our users (and was trivial once I was not using the simulator).

To post a comment you must log in.
Revision history for this message
Mike McCracken (mikemc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Music/UOAppDelegate.m'
2--- Music/UOAppDelegate.m 2013-02-11 03:55:13 +0000
3+++ Music/UOAppDelegate.m 2013-02-13 18:38:21 +0000
4@@ -31,7 +31,7 @@
5 #import "UOAppDelegate.h"
6 #import "UOAuthManager.h"
7 #import "U1LocalMusicServer.h"
8-#import "StreamingPlayer.h"
9+#import "UOPlayer.h"
10 #import <Crashlytics/Crashlytics.h>
11
12 #if TARGET_IPHONE_SIMULATOR
13@@ -66,7 +66,6 @@
14
15 /* Set up the local music server for serving music */
16 _musicServer = [U1LocalMusicServer new];
17- [[StreamingPlayer sharedStreamingPlayer] recoverState];
18
19 [self checkAuthentication];
20 return YES;
21@@ -90,6 +89,36 @@
22 }
23 }
24
25+#pragma mark - Remote control events
26+
27+/* It's usually suggested that this be implemented at the View Controller level.
28+ No. Let these events bubble to a single place.
29+ */
30+- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
31+ if (![[UOPlayer player] currentSong]) {
32+ return;
33+ }
34+
35+ if (event.type == UIEventTypeRemoteControl) {
36+ switch (event.subtype) {
37+ case UIEventSubtypeRemoteControlPlay:
38+ case UIEventSubtypeRemoteControlPause:
39+ case UIEventSubtypeRemoteControlTogglePlayPause: {
40+ [[UOPlayer player] playPause];
41+ break;
42+ }
43+ case UIEventSubtypeRemoteControlPreviousTrack:
44+ [[UOPlayer player] prev];
45+ break;
46+ case UIEventSubtypeRemoteControlNextTrack:
47+ [[UOPlayer player] next];
48+ break;
49+ default:
50+ break;
51+ }
52+ }
53+}
54+
55 #pragma mark - Core Data stack
56
57 // Returns the managed object context for the application.
58
59=== modified file 'Music/Utilities/UOPlayer.m'
60--- Music/Utilities/UOPlayer.m 2013-02-13 18:38:21 +0000
61+++ Music/Utilities/UOPlayer.m 2013-02-13 18:38:21 +0000
62@@ -252,6 +252,13 @@
63 [player replaceCurrentItemWithPlayerItem:item];
64 [player play];
65
66+ NSDictionary *songInfo = @{MPMediaItemPropertyAlbumArtist: song.albumArtist.name,
67+ MPMediaItemPropertyAlbumTitle: song.album.title,
68+ MPMediaItemPropertyTitle: song.title,
69+ MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:song.art]
70+ };
71+ [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
72+
73 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerSongChanged object:nil];
74 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerStateChanged object:nil];
75 }

Subscribers

People subscribed via source and target branches