Commit f6e5ffb4 authored by Allan Odgaard's avatar Allan Odgaard Committed by 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: default avatarDavid Fuhrmann <david.fuhrmann@googlemail.com>
parent 933916d7
/*
* 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
......@@ -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;
......
......@@ -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
......
......@@ -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")
......
......@@ -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")];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment