[vlc-commits] [Git][videolan/vlc][master] 6 commits: macosx: Use reliable VLCPlayerCurrentMediaItemChanged notification instead of...

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Apr 15 11:23:28 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
2f16b388 by Claudio Cambra at 2023-04-15T11:08:48+00:00
macosx: Use reliable VLCPlayerCurrentMediaItemChanged notification instead of unreliable VLCPlaylistCurrentItemChanged in straightforward listeners

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

- - - - -
1392281e by Claudio Cambra at 2023-04-15T11:08:48+00:00
macosx: Replace playlist item changed listener in VLCLibraryAudioDataSource with notification handler for VLCPlayerCurrentMediaItemChanged

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

- - - - -
9e2049bd by Claudio Cambra at 2023-04-15T11:08:48+00:00
macosx: Replace handling of playlist current media item changed in VLCRemoteControlService with VLCPlayerCurrentMediaItemChanged handling

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

- - - - -
f090fcef by Claudio Cambra at 2023-04-15T11:08:48+00:00
macosx: Use VLCPlayerCurrentMediaItemChanged to detect change in playing item for VLCInformationWindowController rather than VLCPlaylistCurrentItemChanged

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

- - - - -
e1ef6c08 by Claudio Cambra at 2023-04-15T11:08:48+00:00
macosx: Replace use of VLCPlaylistCurrentItemChanged notification with VLCPlayerCurrentMediaItemChanged notification in VLCPlaybackContinuityController

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

- - - - -
43bc326f by Claudio Cambra at 2023-04-15T11:08:48+00:00
macosx: Replace misleading VLCPlaylistCurrentItemChanged notification and handling with accurate VLCPlaylistCurrentItemIndexChanged

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

- - - - -


9 changed files:

- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/library/audio-library/VLCLibrarySongsTableViewSongPlayingTableCellView.m
- modules/gui/macosx/menus/VLCMainMenu.m
- modules/gui/macosx/os-integration/VLCRemoteControlService.m
- modules/gui/macosx/panels/VLCInformationWindowController.m
- modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
- modules/gui/macosx/playlist/VLCPlaylistController.h
- modules/gui/macosx/playlist/VLCPlaylistController.m
- modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m


Changes:

=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
=====================================
@@ -44,6 +44,7 @@
 #import "extensions/NSString+Helpers.h"
 #import "extensions/NSPasteboardItem+VLCAdditions.h"
 
+#import "playlist/VLCPlayerController.h"
 #import "playlist/VLCPlaylistController.h"
 #import "playlist/VLCPlaylistItem.h"
 #import "playlist/VLCPlaylistModel.h"
@@ -113,45 +114,27 @@ NSString * const VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
                                    name:VLCLibraryModelGenreListUpdated
                                  object:nil];
         [notificationCenter addObserver:self
-                               selector:@selector(playlistItemChanged:)
-                                   name:VLCPlaylistCurrentItemChanged
+                               selector:@selector(currentlyPlayingItemChanged:)
+                                   name:VLCPlayerCurrentMediaItemChanged
                                  object:nil];
     }
 
     return self;
 }
 
-- (void)playlistItemChanged:(NSNotification *)aNotification
+- (void)currentlyPlayingItemChanged:(NSNotification *)aNotification
 {
-    NSParameterAssert(aNotification);
-    VLCPlaylistController *playlistController = (VLCPlaylistController *)aNotification.object;
-    NSAssert(playlistController, @"Should receive valid playlist controller from notification");
-    VLCPlaylistModel *playlistModel = playlistController.playlistModel;
-    NSAssert(playlistModel, @"Should receive valid playlist model");
-
-    // If we use the playlist's currentPlayingItem we will get the same item we had before.
-    // Let's instead grab the playlist item from the playlist model, as we know this is
-    // updated before the VLCPlaylistCurrentItemChanged notification is sent out
-    size_t currentPlaylistIndex = playlistController.currentPlaylistIndex;
-    if (currentPlaylistIndex < 0) {
-        return;
-    }
-
-    VLCPlaylistItem *currentPlayingItem = [playlistModel playlistItemAtIndex:currentPlaylistIndex];
-    if (!currentPlayingItem) {
-        return;
-    }
-
-    VLCInputItem *currentInputItem = currentPlayingItem.inputItem;
-    if (!currentPlayingItem) {
+    VLCPlayerController * const playerController = VLCMain.sharedInstance.playlistController.playerController;
+    VLCInputItem * const currentInputItem = playerController.currentMedia;
+    if (!currentInputItem) {
         return;
     }
 
     if (_currentParentType == VLC_ML_PARENT_UNKNOWN) {
-        NSString *currentItemMrl = currentInputItem.MRL;
+        NSString * const currentItemMrl = currentInputItem.MRL;
 
-        NSUInteger itemIndexInDisplayedCollection = [self->_displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
-            VLCMediaLibraryMediaItem *mediaItem = (VLCMediaLibraryMediaItem *)element;
+        const NSUInteger itemIndexInDisplayedCollection = [self->_displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
+            VLCMediaLibraryMediaItem * const mediaItem = (VLCMediaLibraryMediaItem *)element;
             return [mediaItem.inputItem.MRL isEqualToString:currentItemMrl];
         }];
 


=====================================
modules/gui/macosx/library/audio-library/VLCLibrarySongsTableViewSongPlayingTableCellView.m
=====================================
@@ -35,7 +35,7 @@
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
     [notificationCenter addObserver:self
                            selector:@selector(playStateOrItemChanged:)
-                               name:VLCPlaylistCurrentItemChanged
+                               name:VLCPlayerCurrentMediaItemChanged
                              object:nil];
     [notificationCenter addObserver:self
                            selector:@selector(playStateOrItemChanged:)


=====================================
modules/gui/macosx/menus/VLCMainMenu.m
=====================================
@@ -220,7 +220,7 @@ typedef NS_ENUM(NSInteger, VLCObjectType) {
                              object:nil];
     [notificationCenter addObserver:self
                            selector:@selector(mediaItemChanged:)
-                               name:VLCPlaylistCurrentItemChanged
+                               name:VLCPlayerCurrentMediaItemChanged
                              object:nil];
     [notificationCenter addObserver:self
                            selector:@selector(voutListChanged:)


=====================================
modules/gui/macosx/os-integration/VLCRemoteControlService.m
=====================================
@@ -85,7 +85,7 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
                                  object:nil];
         [notificationCenter addObserver:self
                                selector:@selector(metaDataChangedForCurrentMedia:)
-                                   name:VLCPlaylistCurrentItemChanged
+                                   name:VLCPlayerCurrentMediaItemChanged
                                  object:nil];
         [notificationCenter addObserver:self
                                selector:@selector(playbackStateChanged:)
@@ -147,9 +147,9 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
 
 - (void)metaDataChangedForCurrentMedia:(NSNotification *)aNotification
 {
-    VLCInputItem *inputItem = _playerController.currentMedia;
+    VLCInputItem * const inputItem = _playerController.currentMedia;
 
-    NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
+    NSMutableDictionary * const currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
     [self setTimeInformationForDictionary:currentlyPlayingTrackInfo];
     [self setRateInformationForDictionary:currentlyPlayingTrackInfo];
 
@@ -158,16 +158,16 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
     currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = inputItem.albumName;
     currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([inputItem.trackNumber intValue]);
 
-    vlc_tick_t duration = inputItem.duration;
+    const vlc_tick_t duration = inputItem.duration;
     currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(duration));
     currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyIsLiveStream] = @(duration <= 0);
 
-    NSURL *artworkURL = inputItem.artworkURL;
+    NSURL * const artworkURL = inputItem.artworkURL;
     if (artworkURL) {
-        NSImage *coverArtImage = [[NSImage alloc] initWithContentsOfURL:artworkURL];
+        NSImage * const coverArtImage = [[NSImage alloc] initWithContentsOfURL:artworkURL];
         if (coverArtImage) {
-            MPMediaItemArtwork *mpartwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:coverArtImage.size
-                                                                            requestHandler:^NSImage* _Nonnull(CGSize size) {
+            MPMediaItemArtwork * const mpartwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:coverArtImage.size
+                                                                                   requestHandler:^NSImage* _Nonnull(CGSize size) {
                 return coverArtImage;
             }];
             currentlyPlayingTrackInfo[MPMediaItemPropertyArtwork] = mpartwork;


=====================================
modules/gui/macosx/panels/VLCInformationWindowController.m
=====================================
@@ -85,8 +85,8 @@
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
     if (_mainMenuInstance) {
         [notificationCenter addObserver:self
-                               selector:@selector(currentPlaylistItemChanged:)
-                                   name:VLCPlaylistCurrentItemChanged
+                               selector:@selector(currentPlayingItemChanged:)
+                                   name:VLCPlayerCurrentMediaItemChanged
                                  object:nil];
         [notificationCenter addObserver:self
                                selector:@selector(updateStatistics:)
@@ -216,10 +216,10 @@
     [_lostAudioBuffersTextField setIntValue: 0];
 }
 
-- (void)currentPlaylistItemChanged:(NSNotification *)aNotification
+- (void)currentPlayingItemChanged:(NSNotification *)aNotification
 {
-    VLCPlaylistController *playlistController = [[VLCMain sharedInstance] playlistController];
-    VLCInputItem *currentMediaItem = playlistController.currentlyPlayingInputItem;
+    VLCPlayerController * const playerController = VLCMain.sharedInstance.playlistController.playerController;
+    VLCInputItem * const currentMediaItem = playerController.currentMedia;
     [self setRepresentedInputItem:currentMediaItem];
 }
 


=====================================
modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
=====================================
@@ -67,7 +67,7 @@ static NSString *VLCRecentlyPlayedMediaListKey = @"recentlyPlayedMediaList";
         NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
         [notificationCenter addObserver:self
                                selector:@selector(inputItemChanged:)
-                                   name:VLCPlaylistCurrentItemChanged
+                                   name:VLCPlayerCurrentMediaItemChanged
                                  object:nil];
         [notificationCenter addObserver:self
                                selector:@selector(playbackStatusUpdated:)
@@ -91,15 +91,16 @@ static NSString *VLCRecentlyPlayedMediaListKey = @"recentlyPlayedMediaList";
 
 - (void)inputItemChanged:(NSNotification *)aNotification
 {
-    VLCMain *mainInstance = [VLCMain sharedInstance];
+    VLCPlayerController * const playerController = VLCMain.sharedInstance.playlistController.playerController;
+
     // Cancel pending resume dialogs
     [_resumeDialogController cancel];
 
     // object is hold here and released then it is dead
-    _currentInput = [[mainInstance playlistController] currentlyPlayingInputItem];
+    _currentInput = playerController.currentMedia;
     if (_currentInput) {
-        VLCPlaylistController *playlistController = aNotification.object;
-        [self continuePlaybackWhereYouLeftOff:_currentInput player:playlistController.playerController];
+        [self continuePlaybackWhereYouLeftOff:_currentInput
+                                       player:playerController];
     }
 }
 


=====================================
modules/gui/macosx/playlist/VLCPlaylistController.h
=====================================
@@ -36,7 +36,7 @@ extern NSString *VLCPlaybackOrderChanged;
 extern NSString *VLCPlaybackRepeatChanged;
 extern NSString *VLCPlaybackHasPreviousChanged;
 extern NSString *VLCPlaybackHasNextChanged;
-extern NSString *VLCPlaylistCurrentItemChanged;
+extern NSString *VLCPlaylistCurrentItemIndexChanged;
 extern NSString *VLCPlaylistItemsAdded;
 extern NSString *VLCPlaylistItemsRemoved;
 
@@ -77,7 +77,6 @@ extern NSString *VLCPlaylistItemsRemoved;
  * input of the currently playing item
  @return returns the input item for the currently playing playlist item
  @note the receiver is responsible for releasing the input item
- @note Subscribe to the VLCPlaylistCurrentItemChanged notification to be notified about changes
  */
 @property (readonly, nullable) VLCInputItem *currentlyPlayingInputItem;
 


=====================================
modules/gui/macosx/playlist/VLCPlaylistController.m
=====================================
@@ -38,7 +38,7 @@ NSString *VLCPlaybackOrderChanged = @"VLCPlaybackOrderChanged";
 NSString *VLCPlaybackRepeatChanged = @"VLCPlaybackRepeatChanged";
 NSString *VLCPlaybackHasPreviousChanged = @"VLCPlaybackHasPreviousChanged";
 NSString *VLCPlaybackHasNextChanged = @"VLCPlaybackHasNextChanged";
-NSString *VLCPlaylistCurrentItemChanged = @"VLCPlaylistCurrentItemChanged";
+NSString *VLCPlaylistCurrentItemIndexChanged = @"VLCPlaylistCurrentItemIndexChanged";
 NSString *VLCPlaylistItemsAdded = @"VLCPlaylistItemsAdded";
 NSString *VLCPlaylistItemsRemoved = @"VLCPlaylistItemsRemoved";
 
@@ -57,7 +57,7 @@ NSString *VLCPlaylistItemsRemoved = @"VLCPlaylistItemsRemoved";
 - (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems;
 - (void)playlistPlaybackRepeatUpdated:(enum vlc_playlist_playback_repeat)currentRepeatMode;
 - (void)playlistPlaybackOrderUpdated:(enum vlc_playlist_playback_order)currentOrder;
-- (void)currentPlaylistItemChanged:(size_t)index;
+- (void)currentPlaylistItemIndexChanged:(size_t)index;
 - (void)playlistHasPreviousItem:(BOOL)hasPrevious;
 - (void)playlistHasNextItem:(BOOL)hasNext;
 
@@ -162,13 +162,13 @@ cb_playlist_playback_order_changed(vlc_playlist_t *playlist,
 }
 
 static void
-cb_playlist_current_item_changed(vlc_playlist_t *playlist,
+cb_playlist_current_item_index_changed(vlc_playlist_t *playlist,
                                  ssize_t index,
                                  void *p_data)
 {
     dispatch_async(dispatch_get_main_queue(), ^{
-        VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data;
-        [playlistController currentPlaylistItemChanged:index];
+        VLCPlaylistController * const playlistController = (__bridge VLCPlaylistController *)p_data;
+        [playlistController currentPlaylistItemIndexChanged:index];
     });
 }
 
@@ -202,7 +202,7 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     cb_playlist_items_updated,
     cb_playlist_playback_repeat_changed,
     cb_playlist_playback_order_changed,
-    cb_playlist_current_item_changed,
+    cb_playlist_current_item_index_changed,
     cb_playlist_has_prev_changed,
     cb_playlist_has_next_changed,
 };
@@ -338,11 +338,11 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     [_defaultNotificationCenter postNotificationName:VLCPlaybackOrderChanged object:self];
 }
 
-- (void)currentPlaylistItemChanged:(size_t)index
+- (void)currentPlaylistItemIndexChanged:(size_t)index
 {
     _currentPlaylistIndex = index;
     [_playlistDataSource scrollToCurrentPlaylistItem];
-    [_defaultNotificationCenter postNotificationName:VLCPlaylistCurrentItemChanged object:self];
+    [_defaultNotificationCenter postNotificationName:VLCPlaylistCurrentItemIndexChanged object:self];
 }
 
 - (void)playlistHasPreviousItem:(BOOL)hasPrevious


=====================================
modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m
=====================================
@@ -93,10 +93,6 @@
                            selector:@selector(playerStateUpdated:)
                                name:VLCPlayerStateChanged
                              object:nil];
-    [notificationCenter addObserver:self
-                           selector:@selector(updatePlaybackControls:)
-                               name:VLCPlayerCurrentMediaItemChanged
-                             object:nil];
     [notificationCenter addObserver:self
                            selector:@selector(updateCurrentItemDisplayControls:)
                                name:VLCPlayerCurrentMediaItemChanged



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/73053e6b9a35f49c90747154f386d3546c413228...43bc326f1b0f31871ee66eba00d290f8f7ecb83f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/73053e6b9a35f49c90747154f386d3546c413228...43bc326f1b0f31871ee66eba00d290f8f7ecb83f
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