[vlc-commits] macosx: implement seeking and playback position display within the main window

Felix Paul Kühne git at videolan.org
Mon Feb 11 14:30:56 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Feb 11 13:42:18 2019 +0100| [f195a7269eb8def0c67cafe52d71a117d2fe5fd5] | committer: Felix Paul Kühne

macosx: implement seeking and playback position display within the main window

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f195a7269eb8def0c67cafe52d71a117d2fe5fd5
---

 .../gui/macosx/coreinteraction/VLCInputManager.m   |  2 -
 modules/gui/macosx/extensions/NSString+Helpers.h   | 14 +++++
 modules/gui/macosx/extensions/NSString+Helpers.m   | 17 ++++++
 modules/gui/macosx/main/VLCMain.m                  |  1 -
 .../windows/mainwindow/VLCControlsBarCommon.h      |  1 -
 .../windows/mainwindow/VLCControlsBarCommon.m      | 68 ++++++++++------------
 .../gui/macosx/windows/mainwindow/VLCMainWindow.m  |  6 --
 7 files changed, 63 insertions(+), 46 deletions(-)

diff --git a/modules/gui/macosx/coreinteraction/VLCInputManager.m b/modules/gui/macosx/coreinteraction/VLCInputManager.m
index d75c4d16e6..9b4a20c9fa 100644
--- a/modules/gui/macosx/coreinteraction/VLCInputManager.m
+++ b/modules/gui/macosx/coreinteraction/VLCInputManager.m
@@ -124,7 +124,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
 
             case INPUT_EVENT_DEAD:
                 [inputManager performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
-                [[[VLCMain sharedInstance] mainWindow] performSelectorOnMainThread:@selector(updateTimeSlider) withObject:nil waitUntilDone:NO];
                 break;
 
             default:
@@ -282,7 +281,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
 
 - (void)playbackPositionUpdated
 {
-    [[[VLCMain sharedInstance] mainWindow] updateTimeSlider];
     [[[VLCMain sharedInstance] statusBarIcon] updateProgress];
 }
 
diff --git a/modules/gui/macosx/extensions/NSString+Helpers.h b/modules/gui/macosx/extensions/NSString+Helpers.h
index 7e61b6509b..2489ab59f0 100644
--- a/modules/gui/macosx/extensions/NSString+Helpers.h
+++ b/modules/gui/macosx/extensions/NSString+Helpers.h
@@ -75,6 +75,20 @@ NSImage *imageFromRes(NSString *name);
                                negative:(BOOL)negative;
 
 /**
+ Creates an NSString with the current time of the \c input_item_t
+
+ This method allocates and initializes an NSString with the current
+ elapsed or remaining time of the given input.
+
+ \param the duration
+ \param the current time
+ \param negative   If YES, calculate remaining instead of elapsed time
+ */
++ (instancetype)stringWithDuration:(vlc_tick_t)duration
+                       currentTime:(vlc_tick_t)time
+                          negative:(BOOL)negative;
+
+/**
  Creates an NSString with the given time in seconds
 
  This method allocates and initializes an NSString with the given
diff --git a/modules/gui/macosx/extensions/NSString+Helpers.m b/modules/gui/macosx/extensions/NSString+Helpers.m
index dcddce1036..8dcce48b52 100644
--- a/modules/gui/macosx/extensions/NSString+Helpers.m
+++ b/modules/gui/macosx/extensions/NSString+Helpers.m
@@ -69,6 +69,23 @@ NSString *const kVLCMediaUnknown = @"Unknown";
     }
 }
 
++ (instancetype)stringWithDuration:(vlc_tick_t)duration
+                       currentTime:(vlc_tick_t)time
+                          negative:(BOOL)negative
+{
+    char psz_time[MSTRTIME_MAX_SIZE];
+
+    if (negative && duration > 0) {
+        vlc_tick_t remaining = (duration > time) ? (duration - time) : 0;
+
+        return [NSString stringWithFormat:@"-%s",
+                secstotimestr(psz_time, (int)SEC_FROM_VLC_TICK(remaining))];
+    } else {
+        return [NSString stringWithUTF8String:
+                secstotimestr(psz_time, (int)SEC_FROM_VLC_TICK(time))];
+    }
+}
+
 + (instancetype)stringWithTimeFromTicks:(vlc_tick_t)time
 {
     char psz_time[MSTRTIME_MAX_SIZE];
diff --git a/modules/gui/macosx/main/VLCMain.m b/modules/gui/macosx/main/VLCMain.m
index c5447681a5..93bf2c355a 100644
--- a/modules/gui/macosx/main/VLCMain.m
+++ b/modules/gui/macosx/main/VLCMain.m
@@ -307,7 +307,6 @@ static VLCMain *sharedInstance = nil;
 
     /* update the main window */
     [[self mainWindow] updateWindow];
-    [[self mainWindow] updateTimeSlider];
     [[self mainWindow] updateVolumeSlider];
 
     // respect playlist-autostart
diff --git a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h
index 24410b783d..a82dcafd08 100644
--- a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h
+++ b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h
@@ -63,7 +63,6 @@
 - (IBAction)timeSliderAction:(id)sender;
 - (IBAction)fullscreen:(id)sender;
 
-- (void)updateTimeSlider;
 - (void)updateControls;
 - (void)setPause;
 - (void)setPlay;
diff --git a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m
index eab9a989c1..747b6cc9a5 100644
--- a/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m
+++ b/modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m
@@ -28,6 +28,8 @@
 #import "main/VLCMain.h"
 #import "main/CompatibilityFixes.h"
 #import "menus/VLCMainMenu.h"
+#import "playlist/VLCPlaylistController.h"
+#import "playlist/VLCPlayerController.h"
 
 /*****************************************************************************
  * VLCControlsBarCommon
@@ -55,7 +57,9 @@
 - (void)awakeFromNib
 {
     [super awakeFromNib];
-    
+
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTimeSlider:) name:VLCPlayerTimeAndPositionChanged object:nil];
+
     _nativeFullscreenMode = var_InheritBool(getIntf(), "macosx-nativefullscreenmode");
 
     [self.dropView setDrawBorder: NO];
@@ -110,6 +114,11 @@
         [self toggleForwardBackwardMode: YES];
 }
 
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
 - (CGFloat)height
 {
     return [self.bottomBarView frame].size.height;
@@ -232,8 +241,7 @@
 
 - (IBAction)timeSliderAction:(id)sender
 {
-    float f_updated;
-    input_thread_t * p_input;
+    float f_updatedDelta;
 
     switch([[NSApp currentEvent] type]) {
         case NSLeftMouseUp:
@@ -247,29 +255,19 @@
             return;
         case NSLeftMouseDown:
         case NSLeftMouseDragged:
-            f_updated = [sender floatValue];
+            f_updatedDelta = [sender floatValue];
             break;
         case NSScrollWheel:
-            f_updated = [sender floatValue];
+            f_updatedDelta = [sender floatValue];
             break;
 
         default:
             return;
     }
-    p_input = pl_CurrentInput(getIntf());
-    if (p_input != NULL) {
-        vlc_value_t pos;
-        NSString * o_time;
-
-        pos.f_float = f_updated / 10000.;
-        var_Set(p_input, "position", pos);
-        [self.timeSlider setFloatValue: f_updated];
-
-        o_time = [NSString stringWithTimeFromInput:p_input
-                                          negative:self.timeField.timeRemaining];
-        [self.timeField setStringValue: o_time];
-        vlc_object_release(p_input);
-    }
+
+    VLCPlayerController *playerController = [[[VLCMain sharedInstance] playlistController] playerController];
+    [playerController setPositionFast:f_updatedDelta / 10000.];
+    [self.timeSlider setFloatValue:f_updatedDelta];
 }
 
 - (IBAction)fullscreen:(id)sender
@@ -280,14 +278,14 @@
 #pragma mark -
 #pragma mark Updaters
 
-- (void)updateTimeSlider
+- (void)updateTimeSlider:(NSNotification *)aNotification;
 {
-    input_thread_t * p_input;
-    p_input = pl_CurrentInput(getIntf());
+    VLCPlayerController *playerController = aNotification.object;
+    input_item_t *p_item = playerController.currentMedia;
 
     [self.timeSlider setHidden:NO];
 
-    if (!p_input) {
+    if (!p_item) {
         // Nothing playing
         [self.timeSlider setKnobHidden:YES];
         [self.timeSlider setFloatValue: 0.0];
@@ -298,27 +296,25 @@
     }
 
     [self.timeSlider setKnobHidden:NO];
+    [self.timeSlider setFloatValue:(10000. * playerController.position)];
 
-    vlc_value_t pos;
-    var_Get(p_input, "position", &pos);
-    [self.timeSlider setFloatValue:(10000. * pos.f_float)];
-
-    vlc_tick_t dur = input_item_GetDuration(input_GetItem(p_input));
-    if (dur == -1) {
+    vlc_tick_t duration = input_item_GetDuration(p_item);
+    bool buffering = playerController.playerState == VLC_PLAYER_STATE_STARTED;
+    if (duration == -1) {
         // No duration, disable slider
         [self.timeSlider setEnabled:NO];
-    } else {
-        input_state_e inputState = var_GetInteger(p_input, "state");
-        bool buffering = (inputState == INIT_S || inputState == OPENING_S);
+    } else if (buffering) {
+        [self.timeSlider setEnabled:NO];
         [self.timeSlider setIndefinite:buffering];
+    } else {
+        [self.timeSlider setEnabled:playerController.seekable];
     }
 
-    NSString *time = [NSString stringWithTimeFromInput:p_input
-                                              negative:self.timeField.timeRemaining];
+    NSString *time = [NSString stringWithDuration:duration
+                                      currentTime:playerController.time
+                                         negative:self.timeField.timeRemaining];
     [self.timeField setStringValue:time];
     [self.timeField setNeedsDisplay:YES];
-
-    vlc_object_release(p_input);
 }
 
 - (void)updateControls
diff --git a/modules/gui/macosx/windows/mainwindow/VLCMainWindow.m b/modules/gui/macosx/windows/mainwindow/VLCMainWindow.m
index 0dacbbe852..2581ace9c5 100644
--- a/modules/gui/macosx/windows/mainwindow/VLCMainWindow.m
+++ b/modules/gui/macosx/windows/mainwindow/VLCMainWindow.m
@@ -570,13 +570,8 @@ static const float f_min_window_height = 307.;
 
 - (void)updateTimeSlider
 {
-    [self.controlsBar updateTimeSlider];
     [self.fspanel updatePositionAndTime];
 
-    [[[VLCMain sharedInstance] voutProvider] updateControlsBarsUsingBlock:^(VLCControlsBarCommon *controlsBar) {
-        [controlsBar updateTimeSlider];
-    }];
-
     [[VLCCoreInteraction sharedInstance] updateAtoB];
 }
 
@@ -658,7 +653,6 @@ static const float f_min_window_height = 307.;
         vlc_object_release(p_input);
     }
 
-    [self updateTimeSlider];
     if ([self.fspanel respondsToSelector:@selector(setSeekable:)])
         [self.fspanel setSeekable: b_seekable];
 



More information about the vlc-commits mailing list