[vlc-commits] macosx: move integration with MPNowPlayingInfoCenter to the new playlist

Felix Paul Kühne git at videolan.org
Mon Mar 11 01:09:03 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Mar 10 23:40:12 2019 +0100| [dcda3df5ceaf3490a69cef7d7e281f1868ed6bf0] | committer: Felix Paul Kühne

macosx: move integration with MPNowPlayingInfoCenter to the new playlist

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dcda3df5ceaf3490a69cef7d7e281f1868ed6bf0
---

 .../gui/macosx/coreinteraction/VLCInputManager.m   | 59 -----------------
 modules/gui/macosx/playlist/VLCPlayerController.m  | 75 +++++++++++++++++++++-
 2 files changed, 74 insertions(+), 60 deletions(-)

diff --git a/modules/gui/macosx/coreinteraction/VLCInputManager.m b/modules/gui/macosx/coreinteraction/VLCInputManager.m
index 7abe71ef9f..377041b400 100644
--- a/modules/gui/macosx/coreinteraction/VLCInputManager.m
+++ b/modules/gui/macosx/coreinteraction/VLCInputManager.m
@@ -20,8 +20,6 @@
 
 #import "VLCInputManager.h"
 
-#import <MediaPlayer/MediaPlayer.h>
-
 #include <vlc_url.h>
 
 #import "coreinteraction/VLCCoreInteraction.h"
@@ -37,11 +35,9 @@
 #import "windows/mainwindow/VLCMainWindow.h"
 #import "windows/video/VLCVoutView.h"
 
-
 @interface VLCInputManager()
 - (void)updateMainMenu;
 - (void)updateMainWindow;
-- (void)updateMetaAndInfo;
 - (void)updateDelays;
 @end
 
@@ -91,7 +87,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
             case INPUT_EVENT_ITEM_INFO:
                 [inputManager performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
                 [inputManager performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
-                [inputManager performSelectorOnMainThread:@selector(updateMetaAndInfo) withObject: nil waitUntilDone:NO];
                 break;
             case INPUT_EVENT_BOOKMARK:
                 break;
@@ -243,8 +238,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
                                                             object:nil];
     }
 
-    [self updateMetaAndInfo];
-
     [self updateMainWindow];
     [self updateDelays];
     [self updateMainMenu];
@@ -287,22 +280,11 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
 
         [[o_main mainMenu] setPause];
         [[o_main mainWindow] setPause];
-
-        if (@available(macOS 10.12.2, *)) {
-            [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePlaying;
-        }
     } else {
         [[o_main mainMenu] setSubmenusEnabled: FALSE];
         [[o_main mainMenu] setPlay];
         [[o_main mainWindow] setPlay];
 
-        if (state == PAUSE_S) {
-
-            if (@available(macOS 10.12.2, *)) {
-                [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePaused;
-            }
-        }
-
         if (state == END_S || state == -1) {
             /* continue playback where you left off */
             if (p_current_input)
@@ -316,10 +298,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
                                                            selector: @selector(onPlaybackHasEnded:)
                                                            userInfo: nil
                                                             repeats: NO];
-
-            if (@available(macOS 10.12.2, *)) {
-                [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStateStopped;
-            }
         }
     }
 
@@ -402,43 +380,6 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
     b_has_spotify_paused = NO;
 }
 
-- (void)updateMetaAndInfo
-{
-    input_item_t *p_input_item = input_GetItem(p_current_input);
-
-    if (!p_input_item) {
-        return;
-    }
-
-    if (@available(macOS 10.12.2, *)) {
-        NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
-
-        currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(input_item_GetDuration(p_input_item)));
-        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(var_GetInteger(p_current_input, "time"));
-        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(var_GetFloat(p_current_input, "rate"));
-
-        char *psz_title = input_item_GetTitle(p_input_item);
-        if (!psz_title)
-            psz_title = input_item_GetName(p_input_item);
-        currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = toNSStr(psz_title);
-        FREENULL(psz_title);
-
-        char *psz_artist = input_item_GetArtist(p_input_item);
-        currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = toNSStr(psz_artist);
-        FREENULL(psz_artist);
-
-        char *psz_album = input_item_GetAlbum(p_input_item);
-        currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = toNSStr(psz_album);
-        FREENULL(psz_album);
-
-        char *psz_track_number = input_item_GetTrackNumber(p_input_item);
-        currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([toNSStr(psz_track_number) intValue]);
-        FREENULL(psz_track_number);
-
-        [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
-    }
-}
-
 - (void)updateMainWindow
 {
     [[o_main mainWindow] updateWindow];
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index bc69519645..9086c9c6e8 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -23,6 +23,8 @@
 #import "VLCPlayerController.h"
 #import "main/VLCMain.h"
 
+#import <MediaPlayer/MediaPlayer.h>
+
 NSString *VLCPlayerCurrentMediaItem = @"VLCPlayerCurrentMediaItem";
 NSString *VLCPlayerCurrentMediaItemChanged = @"VLCPlayerCurrentMediaItemChanged";
 NSString *VLCPlayerStateChanged = @"VLCPlayerStateChanged";
@@ -79,6 +81,7 @@ NSString *VLCPlayerMuteChanged = @"VLCPlayerMuteChanged";
 - (void)recordingChanged:(BOOL)recording;
 - (void)inputStatsUpdated:(VLCInputStats *)inputStats;
 - (void)stopActionChanged:(enum vlc_player_media_stopped_action)stoppedAction;
+- (void)metaDataChangedForInput:(input_item_t *)inputItem;
 
 /* video */
 - (void)fullscreenChanged:(BOOL)isFullscreen;
@@ -289,7 +292,23 @@ static void cb_player_media_stopped_action_changed(vlc_player_t *p_player,
                                                    enum vlc_player_media_stopped_action newAction,
                                                    void *p_data)
 {
+    VLC_UNUSED(p_player);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+        [playerController stopActionChanged:newAction];
+    });
+}
 
+static void cb_player_item_meta_changed(vlc_player_t *p_player,
+                                        input_item_t *p_mediaItem,
+                                        void *p_data)
+{
+    VLC_UNUSED(p_player);
+    input_item_Hold(p_mediaItem);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
+        [playerController metaDataChangedForInput:p_mediaItem];
+    });
 }
 
 static const struct vlc_player_cbs player_callbacks = {
@@ -321,7 +340,7 @@ static const struct vlc_player_cbs player_callbacks = {
     cb_player_stats_changed,
     NULL, //cb_player_atobloop_changed,
     cb_player_media_stopped_action_changed,
-    NULL, //cb_player_item_meta_changed,
+    cb_player_item_meta_changed,
     NULL, //cb_player_item_epg_changed,
     NULL, //cb_player_subitems_changed,
     NULL, //cb_player_vout_list_changed,
@@ -488,6 +507,39 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
     vlc_player_Unlock(_p_player);
 }
 
+- (void)metaDataChangedForInput:(input_item_t *)inputItem
+{
+    if (@available(macOS 10.12.2, *)) {
+        NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
+
+        currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(input_item_GetDuration(inputItem)));
+        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(SEC_FROM_VLC_TICK([self time]));
+        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @([self playbackRate]);
+
+        char *psz_title = input_item_GetTitle(inputItem);
+        if (!psz_title)
+            psz_title = input_item_GetName(inputItem);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = toNSStr(psz_title);
+        FREENULL(psz_title);
+
+        char *psz_artist = input_item_GetArtist(inputItem);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = toNSStr(psz_artist);
+        FREENULL(psz_artist);
+
+        char *psz_album = input_item_GetAlbum(inputItem);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = toNSStr(psz_album);
+        FREENULL(psz_album);
+
+        char *psz_track_number = input_item_GetTrackNumber(inputItem);
+        currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([toNSStr(psz_track_number) intValue]);
+        FREENULL(psz_track_number);
+
+        [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
+    }
+
+    input_item_Release(inputItem);
+}
+
 - (void)nextVideoFrame
 {
     vlc_player_Lock(_p_player);
@@ -534,6 +586,27 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
     _playerState = state;
     [_defaultNotificationCenter postNotificationName:VLCPlayerStateChanged
                                               object:self];
+
+    if (@available(macOS 10.12.2, *)) {
+        switch (_playerState) {
+            case VLC_PLAYER_STATE_PLAYING:
+                [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePlaying;
+                break;
+
+            case VLC_PLAYER_STATE_PAUSED:
+                [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePaused;
+                break;
+
+            case VLC_PLAYER_STATE_STOPPED:
+            case VLC_PLAYER_STATE_STOPPING:
+                [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStateStopped;
+                break;
+
+            default:
+                [MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStateUnknown;
+                break;
+        }
+    }
 }
 
 - (void)errorChanged:(enum vlc_player_error)error



More information about the vlc-commits mailing list