[vlc-commits] [Git][videolan/vlc][master] 6 commits: macosx: Stop trying to always check if iTunes, Apple Music and Spotify are...

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Tue Mar 7 18:02:54 UTC 2023



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
6e7e23eb by Claudio Cambra at 2023-03-07T17:44:08+00:00
macosx: Stop trying to always check if iTunes, Apple Music and Spotify are available, fixing recurring freezing when player state changes

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
35b57641 by Claudio Cambra at 2023-03-07T17:44:08+00:00
macosx: Name Apple Music related variables properly

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
26b0657d by Claudio Cambra at 2023-03-07T17:44:08+00:00
macosx: Don't bother looking for Apple Music on macOS below 10.15, and conversely don't bother looking for iTunes on macOS above 10.15

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
364988df by Claudio Cambra at 2023-03-07T17:44:08+00:00
macosx: Asynchronously fetch other music apps on VLC launch and fully eliminate hiccups on clicking play

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
ef5da7f9 by Claudio Cambra at 2023-03-07T17:44:08+00:00
macosx: Apply stopOtherAudioPlaybackApps to resumeOtherAudioPlaybackApps in VLCPlayerController

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
394232d6 by Claudio Cambra at 2023-03-07T17:44:08+00:00
macosx: Define the different application pointers to have playback stopped/started as internal atomic properties

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


1 changed file:

- modules/gui/macosx/playlist/VLCPlayerController.m


Changes:

=====================================
modules/gui/macosx/playlist/VLCPlayerController.m
=====================================
@@ -92,11 +92,15 @@ const CGFloat VLCVolumeDefault = 1.;
     /* iTunes/Apple Music/Spotify play/pause support */
     BOOL _iTunesPlaybackWasPaused;
     BOOL _appleMusicPlaybackWasPaused;
-    BOOL _SpotifyPlaybackWasPaused;
+    BOOL _spotifyPlaybackWasPaused;
 
     NSTimer *_playbackHasTruelyEndedTimer;
 }
 
+ at property (readwrite, atomic) iTunesApplication *appleMusicApp;
+ at property (readwrite, atomic) iTunesApplication *iTunesApp;
+ at property (readwrite, atomic) SpotifyApplication *spotifyApp;
+
 - (void)currentMediaItemChanged:(input_item_t *)newMediaItem;
 - (void)stateChanged:(enum vlc_player_state)state;
 - (void)errorChanged:(enum vlc_player_error)error;
@@ -620,6 +624,22 @@ static int BossCallback(vlc_object_t *p_this,
         _remoteControlService = [[VLCRemoteControlService alloc] init];
         [_remoteControlService subscribeToRemoteCommands];
     }
+
+    dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
+        if (@available(macOS 10.15, *)) {
+            self.appleMusicApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.Music"];
+        } else {
+            self.iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
+        }
+
+        self.spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            if (self->_playerState == VLC_PLAYER_STATE_PLAYING || self->_playerState == VLC_PLAYER_STATE_STARTED) {
+                [self stopOtherAudioPlaybackApps];
+            }
+        });
+    });
 }
 
 - (void)applicationWillTerminate:(NSNotification *)aNotification
@@ -854,41 +874,45 @@ static int BossCallback(vlc_object_t *p_this,
     if (controlOtherPlayers <= 0)
         return;
 
-    // pause iTunes
-    if (!_iTunesPlaybackWasPaused) {
-        iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
-        if (iTunesApp && [iTunesApp isRunning]) {
-            if ([iTunesApp playerState] == iTunesEPlSPlaying) {
-                msg_Dbg(p_intf, "pausing iTunes");
-                [iTunesApp pause];
-                _iTunesPlaybackWasPaused = YES;
-            }
+    // Don't bother looking for Apple Music on macOS below 10.15, and conversely
+    // don't bother looking for iTunes on macOS above 10.15
+    if (@available(macOS 10.15, *)) {
+        // Pause Apple Music playback
+        iTunesApplication *appleMusic = self.appleMusicApp;
+        if (appleMusic != nil &&
+            !_appleMusicPlaybackWasPaused &&
+            [appleMusic isRunning] &&
+            [appleMusic playerState] == iTunesEPlSPlaying) {
+
+            msg_Dbg(p_intf, "pausing Apple Music");
+            [appleMusic pause];
+            _appleMusicPlaybackWasPaused = YES;
         }
-    }
-
-    if (!_appleMusicPlaybackWasPaused) {
-        iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.Music"];
-        if (iTunesApp && [iTunesApp isRunning]) {
-            if ([iTunesApp playerState] == iTunesEPlSPlaying) {
-                msg_Dbg(p_intf, "pausing Apple Music");
-                [iTunesApp pause];
-                _appleMusicPlaybackWasPaused = YES;
-            }
+    } else {
+        iTunesApplication *iTunes = self.iTunesApp;
+        if (iTunes != nil &&
+            !_iTunesPlaybackWasPaused &&
+            [iTunes isRunning] &&
+            [iTunes playerState] == iTunesEPlSPlaying) {
+            // Pause iTunes playback
+            msg_Dbg(p_intf, "pausing iTunes");
+            [iTunes pause];
+            _iTunesPlaybackWasPaused = YES;
         }
     }
 
-    // pause Spotify
-    if (!_SpotifyPlaybackWasPaused) {
-        SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
-        if (spotifyApp) {
-            if ([spotifyApp respondsToSelector:@selector(isRunning)] && [spotifyApp respondsToSelector:@selector(playerState)]) {
-                if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePlaying) {
-                    msg_Dbg(p_intf, "pausing Spotify");
-                    [spotifyApp pause];
-                    _SpotifyPlaybackWasPaused = YES;
-                }
-            }
-        }
+    // Pause Spotify
+    SpotifyApplication *spotify = self.spotifyApp;
+    if (spotify != nil &&
+        !_spotifyPlaybackWasPaused &&
+        [spotify respondsToSelector:@selector(isRunning)] &&
+        [spotify respondsToSelector:@selector(playerState)] &&
+        [spotify isRunning] &&
+        [spotify playerState] == kSpotifyPlayerStatePlaying) {
+
+        msg_Dbg(p_intf, "pausing Spotify");
+        [spotify pause];
+        _spotifyPlaybackWasPaused = YES;
     }
 }
 
@@ -896,42 +920,44 @@ static int BossCallback(vlc_object_t *p_this,
 {
     intf_thread_t *p_intf = getIntf();
     if (var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
-        if (_iTunesPlaybackWasPaused) {
-            iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
-            if (iTunesApp && [iTunesApp isRunning]) {
-                if ([iTunesApp playerState] == iTunesEPlSPaused) {
-                    msg_Dbg(p_intf, "unpausing iTunes");
-                    [iTunesApp playpause];
-                }
+        if (@available(macOS 10.15, *)) {
+            iTunesApplication *appleMusic = self.appleMusicApp;
+            if (appleMusic != nil &&
+                _appleMusicPlaybackWasPaused &&
+                [appleMusic isRunning] &&
+                [appleMusic playerState] == iTunesEPlSPaused) {
+
+                msg_Dbg(p_intf, "unpausing Apple Music");
+                [appleMusic playpause];
             }
-        }
-
-        if (_appleMusicPlaybackWasPaused) {
-            iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.Music"];
-            if (iTunesApp && [iTunesApp isRunning]) {
-                if ([iTunesApp playerState] == iTunesEPlSPaused) {
-                    msg_Dbg(p_intf, "unpausing Apple Music");
-                    [iTunesApp playpause];
-                }
+        } else {
+            iTunesApplication *iTunes = self.iTunesApp;
+            if (iTunes != nil &&
+                _iTunesPlaybackWasPaused &&
+                [iTunes isRunning] &&
+                [iTunes playerState] == iTunesEPlSPaused) {
+
+                msg_Dbg(p_intf, "unpausing iTunes");
+                [iTunes playpause];
             }
         }
 
-        if (_SpotifyPlaybackWasPaused) {
-            SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
-            if (spotifyApp) {
-                if ([spotifyApp respondsToSelector:@selector(isRunning)] && [spotifyApp respondsToSelector:@selector(playerState)]) {
-                    if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePaused) {
-                        msg_Dbg(p_intf, "unpausing Spotify");
-                        [spotifyApp play];
-                    }
-                }
-            }
+        SpotifyApplication *spotify = self.spotifyApp;
+        if (spotify != nil &&
+            _spotifyPlaybackWasPaused &&
+            [spotify respondsToSelector:@selector(isRunning)] &&
+            [spotify respondsToSelector:@selector(playerState)] &&
+            [spotify isRunning] &&
+            [spotify playerState] == kSpotifyPlayerStatePaused) {
+
+            msg_Dbg(p_intf, "unpausing Spotify");
+            [spotify play];
         }
     }
 
     _iTunesPlaybackWasPaused = NO;
     _appleMusicPlaybackWasPaused = NO;
-    _SpotifyPlaybackWasPaused = NO;
+    _spotifyPlaybackWasPaused = NO;
 }
 
 - (void)errorChanged:(enum vlc_player_error)error



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1f7f400ff74a80354efb467a5cb41b11a0cc98c8...394232d640aa3d140c50347ee0de8290878f6a6c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1f7f400ff74a80354efb467a5cb41b11a0cc98c8...394232d640aa3d140c50347ee0de8290878f6a6c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list