]> git.sesse.net Git - vlc/commitdiff
macosx: Pause Spotify when video starts
authorAllan Odgaard <git@abetarda.com>
Fri, 14 Feb 2014 12:20:59 +0000 (19:20 +0700)
committerDavid Fuhrmann <david.fuhrmann@googlemail.com>
Sun, 16 Feb 2014 18:28:16 +0000 (19:28 +0100)
This mimics the current iTunes support and behavior is controlled by the same setting.

Signed-off-by: David Fuhrmann <david.fuhrmann@googlemail.com>
modules/gui/macosx/Spotify.h [new file with mode: 0644]
modules/gui/macosx/intf.h
modules/gui/macosx/intf.m
modules/gui/macosx/macosx.m
modules/gui/macosx/simple_prefs.m

diff --git a/modules/gui/macosx/Spotify.h b/modules/gui/macosx/Spotify.h
new file mode 100644 (file)
index 0000000..097163a
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Spotify.h
+ */
+
+#import <AppKit/AppKit.h>
+#import <ScriptingBridge/ScriptingBridge.h>
+
+OSType const kSpotifyPlayerStateStopped = 'kPSS';
+OSType const kSpotifyPlayerStatePlaying = 'kPSP';
+OSType const kSpotifyPlayerStatePaused  = 'kPSp';
+
+@interface SpotifyApplication : SBApplication
+@property (readonly) OSType playerState;  // is Spotify stopped, paused, or playing?
+- (void)play;
+- (void)pause;
+@end
index 3fae0e97fde8775bba12e1204b57d711461aa64b..bda8cf815b3b7970cc48ef29ede4cf2978cbc5dd 100644 (file)
@@ -125,8 +125,9 @@ struct intf_sys_t
 
     VLCVoutWindowController *o_vout_controller;
 
-    /* iTunes play/pause support */
+    /* iTunes/Spotify play/pause support */
     BOOL b_has_itunes_paused;
+    BOOL b_has_spotify_paused;
     NSTimer *o_itunes_play_timer;
 
     BOOL b_playlist_updated_selector_in_queue;
index 5ed847d8669330eb45928e66723c1a0399418bf8..9a8760443d3cde5dce3e958c584a9e80df3ca8cb 100644 (file)
@@ -72,6 +72,7 @@
 #import <Sparkle/Sparkle.h>                 /* we're the update delegate */
 
 #import "iTunes.h"
+#import "Spotify.h"
 
 /*****************************************************************************
  * Local prototypes.
@@ -1411,18 +1412,28 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 - (void)resumeItunesPlayback:(id)sender
 {
-    if (b_has_itunes_paused && var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
-        iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
-        if (iTunesApp && [iTunesApp isRunning]) {
-            if ([iTunesApp playerState] == iTunesEPlSPaused) {
-                msg_Dbg(p_intf, "Unpause iTunes...");
-                [iTunesApp playpause];
+    if (var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
+        if (b_has_itunes_paused) {
+            iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
+            if (iTunesApp && [iTunesApp isRunning]) {
+                if ([iTunesApp playerState] == iTunesEPlSPaused) {
+                    msg_Dbg(p_intf, "Unpause iTunes...");
+                    [iTunesApp playpause];
+                }
             }
         }
 
+        if (b_has_spotify_paused) {
+            SpotifyApplication *spotifyApp = [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
+            if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePaused) {
+                msg_Dbg(p_intf, "Unpause Spotify...");
+                [spotifyApp play];
+            }
+        }
     }
 
     b_has_itunes_paused = NO;
+    b_has_spotify_paused = NO;
     o_itunes_play_timer = nil;
 }
 
@@ -1443,18 +1454,29 @@ static VLCMain *_o_sharedMainInstance = nil;
     }
 
     if (state == PLAYING_S) {
-        // pause iTunes
-        if (i_control_itunes > 0 && !b_has_itunes_paused) {
-            iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
-            if (iTunesApp && [iTunesApp isRunning]) {
-                if ([iTunesApp playerState] == iTunesEPlSPlaying) {
-                    msg_Dbg(p_intf, "Pause iTunes...");
-                    [iTunesApp pause];
-                    b_has_itunes_paused = YES;
+        if (i_control_itunes > 0) {
+            // pause iTunes
+            if (!b_has_itunes_paused) {
+                iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
+                if (iTunesApp && [iTunesApp isRunning]) {
+                    if ([iTunesApp playerState] == iTunesEPlSPlaying) {
+                        msg_Dbg(p_intf, "Pause iTunes...");
+                        [iTunesApp pause];
+                        b_has_itunes_paused = YES;
+                    }
                 }
             }
-        }
 
+            // pause Spotify
+            if (!b_has_spotify_paused) {
+                SpotifyApplication *spotifyApp = [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
+                if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePlaying) {
+                    msg_Dbg(p_intf, "Pause Spotify...");
+                    [spotifyApp pause];
+                    b_has_spotify_paused = YES;
+                }
+            }
+        }
 
         /* Declare user activity.
          This wakes the display if it is off, and postpones display sleep according to the users system preferences
index 5b9047c0a9baef89c18513663fd9c0a7bd485f8d..8944d2173c2a7f2cced9838be7f27f824a3e0981 100644 (file)
@@ -121,13 +121,13 @@ void WindowClose  (vout_window_t *);
 #define SIDEBAR_TEXT N_("Show Sidebar")
 #define SIDEBAR_LONGTEXT N_("Shows a sidebar in the main window listing media sources.")
 
-#define ITUNES_TEXT N_("Pause iTunes during VLC playback")
-#define ITUNES_LONGTEXT N_("Pauses iTunes playback when VLC playback starts. If selected, iTunes playback will be resumed again if VLC playback is finished.")
+#define ITUNES_TEXT N_("Control external music players")
+#define ITUNES_LONGTEXT N_("When a video starts playing, VLC will pause supported music players. If selected, external player will be resumed again when playback is finished.")
 
 static const int itunes_list[] =
     { 0, 1, 2 };
 static const char *const itunes_list_text[] = {
-    N_("Do nothing"), N_("Pause iTunes"), N_("Pause and resume iTunes")
+    N_("Do nothing"), N_("Pause iTunes / Spotify"), N_("Pause and resume iTunes / Spotify")
 };
 
 #define VOLUME_MAX_TEXT N_("Maximum Volume displayed")
index 8eb67f20a553cc296916c6ed4bacad98ca975648..980d6e8756303406726910acd6bfb2b2a679551f 100644 (file)
@@ -371,7 +371,7 @@ create_toolbar_item(NSString * o_itemIdent, NSString * o_name, NSString * o_desc
     [o_intf_pauseminimized_ckb setTitle: _NS("Pause the video playback when minimized")];
     [o_intf_luahttp_box setTitle:_NS("Lua HTTP")];
     [o_intf_luahttppwd_lbl setStringValue:_NS("Password")];
-    [o_intf_pauseitunes_lbl setStringValue:_NS("Pause iTunes during VLC playback")];
+    [o_intf_pauseitunes_lbl setStringValue:_NS("Control external music players")];
 
     /* Subtitles and OSD */
     [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];