[vlc-commits] macosx: implemented both skipping within an item and item changing for the forward /backward buttons (closes #4943)

Felix Paul Kühne git at videolan.org
Tue Jul 26 16:20:24 CEST 2011


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Tue Jul 26 16:20:16 2011 +0200| [1554eb2d74c6afe039873d70897d7242d84ebd54] | committer: Felix Paul Kühne

macosx: implemented both skipping within an item and item changing for the forward/backward buttons (closes #4943)

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

 modules/gui/macosx/MainWindow.h |    5 +++
 modules/gui/macosx/MainWindow.m |   75 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/modules/gui/macosx/MainWindow.h b/modules/gui/macosx/MainWindow.h
index dd8f128..9b71b2b 100644
--- a/modules/gui/macosx/MainWindow.h
+++ b/modules/gui/macosx/MainWindow.h
@@ -77,6 +77,11 @@
     NSImage * o_shuffle_pressed_img;
     NSImage * o_shuffle_on_img;
     NSImage * o_shuffle_on_pressed_img;
+
+    NSTimeInterval last_fwd_event;
+    NSTimeInterval last_bwd_event;
+    BOOL just_triggered_next;
+    BOOL just_triggered_previous;
 }
 + (VLCMainWindow *)sharedInstance;
 
diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index 2c30290..34f0988 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -215,15 +215,82 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [[VLCCoreInteraction sharedInstance] play];
 }
 
-// TODO: we need more advanced handling for the next 2 actions to handling skipping as well
+- (void)resetPreviousButton
+{
+    if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35) {
+        // seems like no further event occured, so let's switch the playback item
+        [[VLCCoreInteraction sharedInstance] previous];
+        just_triggered_previous = NO;
+    }
+}
+
+- (void)resetBackwardSkip
+{
+    // the user stopped skipping, so let's allow him to change the item
+    if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35)
+        just_triggered_previous = NO;
+}
+
 - (IBAction)bwd:(id)sender
 {
-    [[VLCCoreInteraction sharedInstance] previous];
+    if(!just_triggered_previous)
+    {
+        just_triggered_previous = YES;
+        [self performSelector:@selector(resetPreviousButton)
+                   withObject: NULL
+                   afterDelay:0.40];
+    }
+    else
+    {
+        if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
+        {
+            // we just skipped 3 "continous" events, otherwise we are too fast
+            [[VLCCoreInteraction sharedInstance] backward];
+            last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
+            [self performSelector:@selector(resetBackwardSkip)
+                       withObject: NULL
+                       afterDelay:0.40];
+        }
+    }
+}
+
+- (void)resetNextButton
+{
+    if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35) {
+        // seems like no further event occured, so let's switch the playback item
+        [[VLCCoreInteraction sharedInstance] next];
+        just_triggered_next = NO;
+    }
+}
+
+- (void)resetForwardSkip
+{
+    // the user stopped skipping, so let's allow him to change the item
+    if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35)
+        just_triggered_next = NO;
 }
 
 - (IBAction)fwd:(id)sender
 {
-    [[VLCCoreInteraction sharedInstance] next];
+   if(!just_triggered_next)
+    {
+        just_triggered_next = YES;
+        [self performSelector:@selector(resetNextButton)
+                   withObject: NULL
+                   afterDelay:0.40];
+    }
+    else
+    {
+        if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
+        {
+            // we just skipped 3 "continous" events, otherwise we are too fast
+            [[VLCCoreInteraction sharedInstance] forward];
+            last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
+            [self performSelector:@selector(resetForwardSkip)
+                       withObject: NULL
+                       afterDelay:0.40];
+        }
+    }
 }
 
 - (IBAction)stop:(id)sender
@@ -585,4 +652,4 @@ static VLCMainWindow *_o_sharedInstance = nil;
     }
 }
 
- at end
\ No newline at end of file
+ at end



More information about the vlc-commits mailing list