浏览代码

improve updating of nowPlayingInfo - fix a bug where the nowPlayingInfo was not updated for remote commands (from control center) - fix a bug where pause/play was not correctly added to nowPlayingInfo - fix a bug where nowPlayingInfo was not updated when scrubbing

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Tobias Conradi 10 年之前
父节点
当前提交
36952393f8
共有 1 个文件被更改,包括 31 次插入14 次删除
  1. 31 14
      Sources/VLCMovieViewController.m

+ 31 - 14
Sources/VLCMovieViewController.m

@@ -1173,6 +1173,11 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
 
     self.scrubIndicatorView.hidden = YES;
     _isScrubbing = NO;
+
+    /* Since the media player doesn't send play notifications after scrubbing
+     * this is the best place to update the displayed metadata.
+     * We wait for a moment so the media player time is correct. */
+    [self performSelector:@selector(_updateDisplayedMetadata) withObject:nil afterDelay:0.5];
 }
 
 - (void)_updateScrubLabel
@@ -1222,8 +1227,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     if (currentState == VLCMediaPlayerStateBuffering) {
         /* attach delegate */
         _mediaPlayer.media.delegate = self;
-        /* let's update meta data */
-        [self _updateDisplayedMetadata];
 
         /* on-the-fly values through private API */
         [_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[self _resolveFontName]];
@@ -1262,6 +1265,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
         _multiSelectionView.mediaHasChapters = YES;
     else
         _multiSelectionView.mediaHasChapters = NO;
+
+    /* let's update meta data */
+    [self _updateDisplayedMetadata];
 }
 
 - (IBAction)playPause
@@ -2123,21 +2129,32 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     self.videoFilterButton.hidden = mediaIsAudioOnly;
 
     /* don't leak sensitive information to the OS, if passcode lock is enabled */
-    BOOL passcodeLockEnabled = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPasscodeOnKey] boolValue];
+    BOOL passcodeLockDisabled = ![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPasscodeOnKey] boolValue];
 
-    NSMutableDictionary *currentlyPlayingTrackInfo;
-    if (passcodeLockEnabled)
-        currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(_mediaPlayer.media.length.intValue / 1000.), MPMediaItemPropertyPlaybackDuration, @(_mediaPlayer.time.intValue / 1000.), MPNowPlayingInfoPropertyElapsedPlaybackTime, @(_mediaPlayer.rate), MPNowPlayingInfoPropertyPlaybackRate, nil];
-    else {
-        currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: title, MPMediaItemPropertyTitle, @(_mediaPlayer.media.length.intValue / 1000.), MPMediaItemPropertyPlaybackDuration, @(_mediaPlayer.time.intValue / 1000.), MPNowPlayingInfoPropertyElapsedPlaybackTime, @(_mediaPlayer.rate), MPNowPlayingInfoPropertyPlaybackRate, nil];
-        if (artist.length > 0)
-            [currentlyPlayingTrackInfo setObject:artist forKey:MPMediaItemPropertyArtist];
-        if (albumName.length > 0)
-            [currentlyPlayingTrackInfo setObject:albumName forKey:MPMediaItemPropertyAlbumTitle];
-        [currentlyPlayingTrackInfo setObject:[NSNumber numberWithInt:[trackNumber intValue]] forKey:MPMediaItemPropertyAlbumTrackNumber];
+    BOOL isPlaying = _mediaPlayer.isPlaying;
+
+    NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
+    currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(_mediaPlayer.media.length.intValue / 1000.);
+    currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] =  @(_mediaPlayer.time.intValue / 1000.);
+    currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(isPlaying ? _mediaPlayer.rate : 0.0);
+
+    if (passcodeLockDisabled) {
+        if (title) {
+            currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = title;
+        }
+        if (artist.length > 0) {
+            currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = artist;
+        }
+        if (albumName.length > 0) {
+            currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = albumName;
+        }
+        int trackNumberInt = [trackNumber intValue];
+        if (trackNumberInt > 0) {
+            currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @(trackNumberInt);
+        }
         if (self.artworkImageView.image) {
             MPMediaItemArtwork *mpartwork = [[MPMediaItemArtwork alloc] initWithImage:self.artworkImageView.image];
-            [currentlyPlayingTrackInfo setObject:mpartwork forKey:MPMediaItemPropertyArtwork];
+            currentlyPlayingTrackInfo[MPMediaItemPropertyArtwork] = mpartwork;
         }
     }