Commit 49a3687a authored by David Fuhrmann's avatar David Fuhrmann

macosx: add support for pausing iTunes when VLC playback starts, and resume...

macosx: add support for pausing iTunes when VLC playback starts, and resume iTunes playback when VLCs playback is finished

Tested with iTunes 8 - 11.
parent 768657f4
......@@ -3674,7 +3674,7 @@ then
VLC_ADD_OBJCFLAGS([macosx], [-fobjc-exceptions] )
VLC_ADD_PLUGIN([macosx])
VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit -Wl,-framework,CoreAudio -Wl,-framework,SystemConfiguration])
VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit -Wl,-framework,CoreAudio -Wl,-framework,SystemConfiguration -Wl,-framework,ScriptingBridge])
if test ! -d ${CONTRIB_DIR}/Sparkle.framework
then
......
......@@ -83,4 +83,5 @@ SOURCES_macosx = \
ControlsBar.h \
VLCVoutWindowController.m \
VLCVoutWindowController.h \
iTunes.h \
$(NULL)
This diff is collapsed.
......@@ -148,6 +148,10 @@ struct intf_sys_t
IOPMAssertionID userActivityAssertionID;
VLCVoutWindowController *o_vout_controller;
/* iTunes play/pause support */
BOOL b_has_itunes_paused;
NSTimer *o_itunes_play_timer;
}
@property (readonly) VLCVoutWindowController* voutController;
......
......@@ -71,6 +71,8 @@
#import <AddressBook/AddressBook.h> /* for crashlog send mechanism */
#import <Sparkle/Sparkle.h> /* we're the update delegate */
#import "iTunes.h"
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
......@@ -805,6 +807,8 @@ static VLCMain *_o_sharedMainInstance = nil;
if (isTerminating)
return;
[self resumeItunesPlayback:nil];
if (notification == nil)
[[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillTerminateNotification object: nil];
......@@ -1352,14 +1356,53 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_playlist outlineViewSelectionDidChange: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];
}
}
}
b_has_itunes_paused = NO;
o_itunes_play_timer = nil;
}
- (void)playbackStatusUpdated
{
int state = -1;
if (p_current_input) {
state = var_GetInteger(p_current_input, "state");
}
int i_control_itunes = var_InheritInteger(p_intf, "macosx-control-itunes");
// cancel itunes timer if next item starts playing
if (state > -1 && state != END_S && i_control_itunes > 0) {
if (o_itunes_play_timer) {
[o_itunes_play_timer invalidate];
o_itunes_play_timer = 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;
}
}
}
/* Declare user activity.
This wakes the display if it is off, and postpones display sleep according to the users system preferences
Available from 10.7.3 */
......@@ -1414,6 +1457,19 @@ static VLCMain *_o_sharedMainInstance = nil;
msg_Dbg(VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID);
IOPMAssertionRelease(systemSleepAssertionID);
}
if (state == END_S || state == -1) {
if (i_control_itunes > 0) {
if (o_itunes_play_timer) {
[o_itunes_play_timer invalidate];
}
o_itunes_play_timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
target: self
selector: @selector(resumeItunesPlayback:)
userInfo: nil
repeats: NO];
}
}
}
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
......
/*****************************************************************************
* macosx.m: Mac OS X module for vlc
*****************************************************************************
* Copyright (C) 2001-2012 VLC authors and VideoLAN
* Copyright (C) 2001-2013 VLC authors and VideoLAN
* $Id$
*
* Authors: Colin Delacroix <colin@zoy.org>
......@@ -9,6 +9,7 @@
* Florian G. Pflug <fgp@phlo.org>
* Jon Lech Johansen <jon-vl@nanocrew.net>
* Felix Paul Kühne <fkuehne at videolan dot org>
* David Fuhrmann <david dot fuhrmann at googlemail dot com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -119,7 +120,16 @@ 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")
vlc_module_begin ()
#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.")
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")
};
vlc_module_begin()
set_description(N_("Mac OS X interface"))
set_capability("interface", 200)
set_callbacks(OpenIntf, CloseIntf)
......@@ -145,8 +155,10 @@ vlc_module_begin ()
add_bool("macosx-show-playback-buttons", false, JUMPBUTTONS_TEXT, JUMPBUTTONS_LONGTEXT, false)
add_bool("macosx-show-playmode-buttons", true, PLAYMODEBUTTONS_TEXT, PLAYMODEBUTTONS_LONGTEXT, false)
add_bool("macosx-show-sidebar", true, SIDEBAR_TEXT, SIDEBAR_LONGTEXT, false)
add_integer("macosx-control-itunes", 1, ITUNES_TEXT, ITUNES_LONGTEXT, false)
change_integer_list(itunes_list, itunes_list_text)
add_submodule ()
add_submodule()
set_description("Mac OS X Video Output Provider")
set_capability("vout window nsobject", 100)
set_callbacks(WindowOpen, WindowClose)
......@@ -154,5 +166,5 @@ vlc_module_begin ()
add_integer("macosx-vdev", 0, VDEV_TEXT, VDEV_LONGTEXT, false)
add_float_with_range("macosx-opaqueness", 1, 0, 1, OPAQUENESS_TEXT, OPAQUENESS_LONGTEXT, true);
add_bool("macosx-black", true, BLACK_TEXT, BLACK_LONGTEXT, false)
vlc_module_end ()
vlc_module_end()
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