Merge lp:~rockstar/ubuntuone-ios-music/airplay-support into lp:ubuntuone-ios-music

Proposed by Paul Hummer
Status: Merged
Approved by: Paul Hummer
Approved revision: 257
Merged at revision: 255
Proposed branch: lp:~rockstar/ubuntuone-ios-music/airplay-support
Merge into: lp:ubuntuone-ios-music
Diff against target: 86 lines (+31/-8)
2 files modified
Music/Utilities/UOPlayer.m (+30/-7)
U1Music.xcodeproj/project.pbxproj (+1/-1)
To merge this branch: bzr merge lp:~rockstar/ubuntuone-ios-music/airplay-support
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
dobey (community) Approve
Review via email: mp+148312@code.launchpad.net

Commit message

Support airplay

Description of the change

This branch adds airplay support, so any airplay compatible devices can receive the music streaming as well as control play/pause/next/prev AND receive information about the song.

Tested on my AppleTV

To post a comment you must log in.
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

Cool feature :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Music/Utilities/UOPlayer.m'
2--- Music/Utilities/UOPlayer.m 2013-02-13 18:33:19 +0000
3+++ Music/Utilities/UOPlayer.m 2013-02-13 20:34:28 +0000
4@@ -60,6 +60,12 @@
5 [self addObserver:self forKeyPath:@"currentIndex" options:nil context:NULL];
6
7 player = [[AVPlayer alloc] init];
8+ player.allowsAirPlayVideo = NO;
9+ __block id weakself = self;
10+ [player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:NULL usingBlock:^(CMTime time) {
11+ [weakself heartbeat];
12+ }];
13+
14 NSError *error;
15 AVAudioSession *audioSession = [AVAudioSession sharedInstance];
16 [audioSession setDelegate:self];
17@@ -74,6 +80,7 @@
18 }
19
20 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(songComplete) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
21+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(songChanged) name:kPlayerSongChanged object:nil];
22
23 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerStateChanged object:nil];
24 return self;
25@@ -251,13 +258,6 @@
26 AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:song.localURL];
27 [player replaceCurrentItemWithPlayerItem:item];
28 [player play];
29-
30- NSDictionary *songInfo = @{MPMediaItemPropertyAlbumArtist: song.albumArtist.name,
31- MPMediaItemPropertyAlbumTitle: song.album.title,
32- MPMediaItemPropertyTitle: song.title,
33- MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:song.art]
34- };
35- [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
36
37 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerSongChanged object:nil];
38 [[NSNotificationCenter defaultCenter] postNotificationName:kPlayerStateChanged object:nil];
39@@ -278,4 +278,27 @@
40 [self next];
41 }
42
43+- (void)songChanged {
44+ Song *song = [[self currentPlaylist] objectAtIndex:self.currentIndex];
45+ NSDictionary *songInfo = @{MPMediaItemPropertyAlbumTitle: song.album.title,
46+ MPMediaItemPropertyAlbumTrackCount: [NSNumber numberWithInt:[song.album.songs count]],
47+ MPMediaItemPropertyAlbumTrackNumber: [NSNumber numberWithInt:song.track],
48+ MPMediaItemPropertyAlbumArtist: song.albumArtist ? song.albumArtist.name : song.artist.name,
49+ MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:song.art],
50+ MPMediaItemPropertyPlaybackDuration: [NSNumber numberWithInt:song.duration],
51+ MPMediaItemPropertyTitle: song.title,
52+
53+ MPNowPlayingInfoPropertyPlaybackQueueIndex: [NSNumber numberWithInt:self.currentIndex],
54+ MPNowPlayingInfoPropertyPlaybackQueueCount: [NSNumber numberWithInt:[songs count]]
55+ };
56+ [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
57+}
58+
59+- (void)heartbeat {
60+ NSMutableDictionary *songInfo = [[[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo] mutableCopy];
61+ [songInfo setObject:[NSNumber numberWithInt:CMTimeGetSeconds([player currentTime])] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
62+ [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
63+ //NSLog(@"heartbeat");
64+}
65+
66 @end
67
68=== modified file 'U1Music.xcodeproj/project.pbxproj'
69--- U1Music.xcodeproj/project.pbxproj 2013-02-13 04:36:08 +0000
70+++ U1Music.xcodeproj/project.pbxproj 2013-02-13 20:34:28 +0000
71@@ -667,7 +667,6 @@
72 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
73 isa = PBXGroup;
74 children = (
75- 52BC20DB16CB417700E22294 /* CoreMedia.framework */,
76 5268508516AE516B001F65A6 /* RestKit.xcodeproj */,
77 5285158E1604F16B004A1F7C /* UbuntuOneAuthKit.xcodeproj */,
78 93F3346C1247FB78006C6707 /* Music */,
79@@ -702,6 +701,7 @@
80 children = (
81 52BC20D416CB18A100E22294 /* AVFoundation.framework */,
82 5279764815F00B2600F8435F /* libz.dylib */,
83+ 52BC20DB16CB417700E22294 /* CoreMedia.framework */,
84 5257416C16C5653100530CCC /* Crashlytics.framework */,
85 5268510716AEFD20001F65A6 /* MobileCoreServices.framework */,
86 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,

Subscribers

People subscribed via source and target branches