Procházet zdrojové kódy

playback: export meta data about current playback item to OS (close #8883)

Felix Paul Kühne před 12 roky
rodič
revize
16ea53ed9a
1 změnil soubory, kde provedl 24 přidání a 0 odebrání
  1. 24 0
      AspenProject/VLCMovieViewController.m

+ 24 - 0
AspenProject/VLCMovieViewController.m

@@ -14,6 +14,7 @@
 #import <CommonCrypto/CommonDigest.h>
 #import "UIDevice+SpeedCategory.h"
 #import "VLCBugreporter.h"
+#import <MediaPlayer/MediaPlayer.h>
 
 #define INPUT_RATE_DEFAULT  1000.
 
@@ -328,6 +329,8 @@
     self.playbackSpeedSlider.value = [self _playbackSpeed];
     [self _updatePlaybackSpeedIndicator];
 
+    [self performSelectorInBackground:@selector(_updateExportedPlaybackInformation) withObject:nil];
+
     _currentAspectRatioMask = 0;
     _mediaPlayer.videoAspectRatio =  NULL;
 
@@ -784,6 +787,9 @@
     float f_value = self.playbackSpeedSlider.value;
     double speed =  pow(2, f_value / 17.);
     self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", speed];
+
+    /* rate changed, so update the exported info */
+    [self performSelectorInBackground:@selector(_updateExportedPlaybackInformation) withObject:nil];
 }
 
 - (float)_playbackSpeed
@@ -880,6 +886,24 @@
         _mediaPlayer.currentVideoTrackIndex = 1;
 }
 
+- (void)_updateExportedPlaybackInformation
+{
+    if (!_mediaItem) {
+        [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
+        return;
+    }
+    MLFile * currentFile = _mediaItem;
+
+    /* we omit artwork for now since we had to read it from storage as we can't access
+     * the artwork cache at the moment - FIXME? */
+    NSDictionary *currentlyPlayingTrackInfo = @{ MPMediaItemPropertyTitle : currentFile.title,
+                                                 MPMediaItemPropertyPlaybackDuration : @(currentFile.duration.intValue / 1000.),
+                                                 MPNowPlayingInfoPropertyElapsedPlaybackTime : @(_mediaPlayer.time.intValue / 1000.),
+                                                 MPNowPlayingInfoPropertyPlaybackRate : @(_mediaPlayer.rate) };
+
+    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
+}
+
 #pragma mark - autorotation
 
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {