Selaa lähdekoodia

[Playback] Enable scrubbing from iOS control center

Mike JS. Choi 7 vuotta sitten
vanhempi
commit
39e9617603

+ 1 - 0
SharedSources/VLCRemoteControlService.h

@@ -24,6 +24,7 @@
 - (void)remoteControlService:(VLCRemoteControlService *)rcs jumpBackwardInSeconds:(NSTimeInterval)seconds;
 - (NSInteger)remoteControlServiceNumberOfMediaItemsinList:(VLCRemoteControlService *)rcs;
 - (void)remoteControlService:(VLCRemoteControlService *)rcs setPlaybackRate:(CGFloat)playbackRate;
+- (void)remoteControlService:(VLCRemoteControlService *)rcs setCurrentPlaybackTime:(NSTimeInterval)playbackTime;
 
 @end
 

+ 7 - 1
SharedSources/VLCRemoteControlService.m

@@ -27,6 +27,7 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
              cc.skipForwardCommand,
              cc.skipBackwardCommand,
              cc.changePlaybackRateCommand,
+             cc.changePlaybackPositionCommand,
              ];
 }
 
@@ -56,7 +57,7 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
     commandCenter.changeShuffleModeCommand.enabled = NO;
     commandCenter.seekForwardCommand.enabled = NO;
     commandCenter.seekBackwardCommand.enabled = NO;
-    commandCenter.changePlaybackPositionCommand.enabled = NO;
+    commandCenter.changePlaybackPositionCommand.enabled = YES;
 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     NSNumber *forwardSkip = [defaults valueForKey:kVLCSettingPlaybackForwardSkipLength];
@@ -125,6 +126,11 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
         [_remoteControlServiceDelegate remoteControlService:self setPlaybackRate:rateEvent.playbackRate];
         return MPRemoteCommandHandlerStatusSuccess;
     }
+    if (event.command == cc.changePlaybackPositionCommand) {
+        MPChangePlaybackPositionCommandEvent *positionEvent = (MPChangePlaybackPositionCommandEvent *)event;
+        [_remoteControlServiceDelegate remoteControlService:self setCurrentPlaybackTime:positionEvent.positionTime];
+        return MPRemoteCommandHandlerStatusSuccess;
+    }
     NSAssert(NO, @"remote control event not handled");
     APLog(@"%s Wasn't able to handle remote control event: %@",__PRETTY_FUNCTION__,event);
     return MPRemoteCommandHandlerStatusCommandFailed;

+ 7 - 0
Sources/VLCPlaybackController.m

@@ -1263,6 +1263,13 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
 {
     self.playbackRate = playbackRate;
 }
+
+- (void)remoteControlService:(VLCRemoteControlService *)rcs setCurrentPlaybackTime:(NSTimeInterval)playbackTime
+{
+    float positionDiff = playbackTime - [self.metadata.elapsedPlaybackTime floatValue];
+    [_mediaPlayer jumpForward:positionDiff];
+}
+
 #pragma mark - helpers
 
 - (NSDictionary *)mediaOptionsDictionary