0

In a basic audio AVPlayer instance, we're playing back an HLS stream and setting the Now Playing info (successfully), but cannot access the properties of the MPNowPlayingInfoCenter that are being set.

The category and active status of our AVAudioSession and are receiving remote control events without issue as well.

NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
[properties setObject:title forKey:MPMediaItemPropertyTitle];
// Set several other properties

MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
[center setNowPlayingInfo:properties];

// Works! The lock screen successfully shows the title and other properties

NSLog("%@", [center nowPlayingInfo]);

The NSLog prints a very default-looking dictionary containing only a MPNowPlayingInfoPropertyPlaybackRate of 0 - which is not accurate anyway as the audio is playing back during the log.

We want to retrieve the currently-set dictionary of properties, update a few, and set them again (for things like album art updates, play/pause timings, etc). What are we missing?

Community
  • 1
  • 1
jterry
  • 6,209
  • 2
  • 30
  • 36

1 Answers1

0

try the following to retrieve the current properties;

 NSMutableDictionary *playInfo = [NSMutableDictionary dictionaryWithDictionary:[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo] ;

And set/update properties as follows;

[playInfo setObject:[NSNumber numberWithFloat: 1.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
[playInfo setObject:[NSNumber numberWithDouble:songDuration] forKey:MPMediaItemPropertyPlaybackDuration];

[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = playInfo;
MDB983
  • 2,444
  • 17
  • 20
  • Thanks @MDB983- but this is the same approach I have in the first 6 lines above to set the values. When you log `[[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo]` after your code, do you get the full feature set printed out? – jterry Apr 28 '14 at 21:58
  • I can inspect a breakpoint in my code, and yes, playInfo shows a number of key/value pairs. Obviously these are values that you have set previously. – MDB983 Apr 28 '14 at 22:12
  • Here is an Log i just grabbed from a player i have. info { MPNowPlayingInfoPropertyPlaybackRate = 1; artist = "Corinne Bailey Rae"; artwork = ""; playbackDuration = "215.4579591836735"; title = "Put Your Records On"; } All of these properties were previously set elsewhere. – MDB983 Apr 28 '14 at 22:20
  • Right - not `playInfo`, but the actual `defaultCenter`'s `nowPlayingInfo`... immediately after setting the value, I can't access the `MPNowPlayingInfoCenter`'s values. Really strange. – jterry Apr 28 '14 at 23:10
  • That is odd, just changed my nslog to read NSLog("%@", [center nowPlayingInfo]); after setting the new values and i'm getting all the new values back. – MDB983 Apr 28 '14 at 23:41