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
=== modified file 'Music/UOAppDelegate.m'
--- Music/UOAppDelegate.m 2013-02-11 03:55:13 +0000
+++ Music/UOAppDelegate.m 2013-02-13 18:38:21 +0000
@@ -31,7 +31,7 @@
31#import "UOAppDelegate.h"31#import "UOAppDelegate.h"
32#import "UOAuthManager.h"32#import "UOAuthManager.h"
33#import "U1LocalMusicServer.h"33#import "U1LocalMusicServer.h"
34#import "StreamingPlayer.h"34#import "UOPlayer.h"
35#import <Crashlytics/Crashlytics.h>35#import <Crashlytics/Crashlytics.h>
3636
37#if TARGET_IPHONE_SIMULATOR37#if TARGET_IPHONE_SIMULATOR
@@ -66,7 +66,6 @@
66 66
67 /* Set up the local music server for serving music */67 /* Set up the local music server for serving music */
68 _musicServer = [U1LocalMusicServer new];68 _musicServer = [U1LocalMusicServer new];
69 [[StreamingPlayer sharedStreamingPlayer] recoverState];
7069
71 [self checkAuthentication];70 [self checkAuthentication];
72 return YES;71 return YES;
@@ -90,6 +89,36 @@
90 }89 }
91}90}
9291
92#pragma mark - Remote control events
93
94/* It's usually suggested that this be implemented at the View Controller level.
95 No. Let these events bubble to a single place.
96 */
97- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
98 if (![[UOPlayer player] currentSong]) {
99 return;
100 }
101
102 if (event.type == UIEventTypeRemoteControl) {
103 switch (event.subtype) {
104 case UIEventSubtypeRemoteControlPlay:
105 case UIEventSubtypeRemoteControlPause:
106 case UIEventSubtypeRemoteControlTogglePlayPause: {
107 [[UOPlayer player] playPause];
108 break;
109 }
110 case UIEventSubtypeRemoteControlPreviousTrack:
111 [[UOPlayer player] prev];
112 break;
113 case UIEventSubtypeRemoteControlNextTrack:
114 [[UOPlayer player] next];
115 break;
116 default:
117 break;
118 }
119 }
120}
121
93#pragma mark - Core Data stack122#pragma mark - Core Data stack
94123
95// Returns the managed object context for the application.124// Returns the managed object context for the application.
96125
=== modified file 'Music/Utilities/UOPlayer.m'
--- Music/Utilities/UOPlayer.m 2013-02-13 18:38:21 +0000
+++ Music/Utilities/UOPlayer.m 2013-02-13 18:38:21 +0000
@@ -252,6 +252,13 @@
252 [player replaceCurrentItemWithPlayerItem:item];252 [player replaceCurrentItemWithPlayerItem:item];
253 [player play];253 [player play];
254 254
255 NSDictionary *songInfo = @{MPMediaItemPropertyAlbumArtist: song.albumArtist.name,
256 MPMediaItemPropertyAlbumTitle: song.album.title,
257 MPMediaItemPropertyTitle: song.title,
258 MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:song.art]
259 };
260 [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
261
255 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerSongChanged object:nil];262 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerSongChanged object:nil];
256 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerStateChanged object:nil];263 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerStateChanged object:nil];
257}264}

Subscribers

People subscribed via source and target branches