[vlc-commits] macosx/coreinteraction: reimplement play/pause toggle

Felix Paul Kühne git at videolan.org
Tue Mar 5 10:26:13 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Mar  4 23:11:21 2019 +0100| [9764ef67a6707e8f39e99d9078de7035926beefe] | committer: Felix Paul Kühne

macosx/coreinteraction: reimplement play/pause toggle

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

 modules/gui/macosx/coreinteraction/VLCCoreInteraction.m | 15 ++++++++-------
 modules/gui/macosx/playlist/VLCPlayerController.h       |  5 +++++
 modules/gui/macosx/playlist/VLCPlayerController.m       | 12 ++++++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m b/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
index 86c058543e..e278889e75 100644
--- a/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
+++ b/modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
@@ -31,6 +31,7 @@
 #import "main/VLCMain.h"
 #import "coreinteraction/VLCClickerManager.h"
 #import "playlist/VLCPlaylistController.h"
+#import "playlist/VLCPlayerController.h"
 #import "playlist/VLCPlaylistModel.h"
 #import "windows/VLCOpenWindowController.h"
 
@@ -117,18 +118,18 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
 
 - (void)playOrPause
 {
-    input_thread_t *p_input = pl_CurrentInput(getIntf());
-    playlist_t *p_playlist = pl_Get(getIntf());
+    VLCMain *mainInstance = [VLCMain sharedInstance];
+    VLCPlaylistController *playlistController = mainInstance.playlistController;
+    input_item_t *p_input_item = playlistController.currentlyPlayingInputItem;
 
-    if (p_input) {
-        playlist_TogglePause(p_playlist);
-        vlc_object_release(p_input);
+    if (p_input_item) {
+        [playlistController.playerController togglePlayPause];
+        input_item_Release(p_input_item);
     } else {
-        VLCMain *mainInstance = [VLCMain sharedInstance];
         if (mainInstance.playlistController.playlistModel.numberOfPlaylistItems == 0)
             [[mainInstance open] openFileGeneric];
         else
-            [mainInstance.playlistController startPlaylist];
+            [playlistController startPlaylist];
     }
 }
 
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index b51c30233b..2170292f57 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -172,6 +172,11 @@ extern NSString *VLCPlayerMuteChanged;
 - (void)resume;
 
 /**
+ * Convinience method to either start or pause playback
+ */
+- (void)togglePlayPause;
+
+/**
  * Stop the current playback
  */
 - (void)stop;
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index 8820cee9f1..2112561881 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -387,6 +387,18 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
     vlc_player_Unlock(_p_player);
 }
 
+- (void)togglePlayPause
+{
+    vlc_player_Lock(_p_player);
+    if (_playerState == VLC_PLAYER_STATE_PLAYING) {
+        vlc_player_Pause(_p_player);
+    } else if (_playerState == VLC_PLAYER_STATE_PAUSED) {
+        vlc_player_Resume(_p_player);
+    } else
+        vlc_player_Start(_p_player);
+    vlc_player_Unlock(_p_player);
+}
+
 - (void)stop
 {
     vlc_player_Lock(_p_player);



More information about the vlc-commits mailing list