[vlc-commits] macosx: Pause Spotify when video starts
Allan Odgaard
git at videolan.org
Sun Feb 16 19:35:12 CET 2014
vlc | branch: master | Allan Odgaard <git at abetarda.com> | Fri Feb 14 19:20:59 2014 +0700| [f6e5ffb4e6e3caf097ac7774b9fd8843f4a73e0b] | committer: David Fuhrmann
macosx: Pause Spotify when video starts
This mimics the current iTunes support and behavior is controlled by the same setting.
Signed-off-by: David Fuhrmann <david.fuhrmann at googlemail.com>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f6e5ffb4e6e3caf097ac7774b9fd8843f4a73e0b
---
modules/gui/macosx/Spotify.h | 16 ++++++++++++
modules/gui/macosx/intf.h | 3 ++-
modules/gui/macosx/intf.m | 52 ++++++++++++++++++++++++++-----------
modules/gui/macosx/macosx.m | 6 ++---
modules/gui/macosx/simple_prefs.m | 2 +-
5 files changed, 59 insertions(+), 20 deletions(-)
diff --git a/modules/gui/macosx/Spotify.h b/modules/gui/macosx/Spotify.h
new file mode 100644
index 0000000..097163a
--- /dev/null
+++ b/modules/gui/macosx/Spotify.h
@@ -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';
+
+ at interface SpotifyApplication : SBApplication
+ at property (readonly) OSType playerState; // is Spotify stopped, paused, or playing?
+- (void)play;
+- (void)pause;
+ at end
diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index 3fae0e9..bda8cf8 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -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;
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 5ed847d..9a876044 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -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
diff --git a/modules/gui/macosx/macosx.m b/modules/gui/macosx/macosx.m
index 5b9047c..8944d21 100644
--- a/modules/gui/macosx/macosx.m
+++ b/modules/gui/macosx/macosx.m
@@ -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")
diff --git a/modules/gui/macosx/simple_prefs.m b/modules/gui/macosx/simple_prefs.m
index 8eb67f2..980d6e8 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -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")];
More information about the vlc-commits
mailing list