[vlc-commits] [Git][videolan/vlc][master] 3 commits: macosx: Scroll to currently-playing item automatically in library songs table view

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sat Dec 24 09:44:44 UTC 2022



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


Commits:
5b408d81 by Claudio Cambra at 2022-12-24T09:29:20+00:00
macosx: Scroll to currently-playing item automatically in library songs table view

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

- - - - -
14655e1c by Claudio Cambra at 2022-12-24T09:29:20+00:00
macosx: Work around issue where playlist controller will return previously playing item when called immediately after notification of item changed

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

- - - - -
2cc6bcc8 by Claudio Cambra at 2022-12-24T09:29:20+00:00
macosx: Add guard for out of bounds indexes provided as arguments for VLCPlaylistModel's playlistItemAtIndex

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

- - - - -


2 changed files:

- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
- modules/gui/macosx/playlist/VLCPlaylistModel.m


Changes:

=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
=====================================
@@ -24,6 +24,7 @@
 
 #import "main/VLCMain.h"
 
+#import "library/VLCInputItem.h"
 #import "library/VLCLibraryWindow.h"
 #import "library/VLCLibraryNavigationStack.h"
 #import "library/VLCLibraryModel.h"
@@ -41,6 +42,11 @@
 #import "library/audio-library/VLCLibrarySongsTableViewSongPlayingTableCellView.h"
 
 #import "extensions/NSString+Helpers.h"
+
+#import "playlist/VLCPlaylistController.h"
+#import "playlist/VLCPlaylistItem.h"
+#import "playlist/VLCPlaylistModel.h"
+
 #import "views/VLCImageView.h"
 #import "views/VLCSubScrollView.h"
 
@@ -97,11 +103,55 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
                                selector:@selector(libraryModelUpdated:)
                                    name:VLCLibraryModelGenreListUpdated
                                  object:nil];
+        [notificationCenter addObserver:self
+                               selector:@selector(playlistItemChanged:)
+                                   name:VLCPlaylistCurrentItemChanged
+                                 object:nil];
     }
 
     return self;
 }
 
+- (void)playlistItemChanged:(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) {
+        return;
+    }
+
+    if (_currentParentType == VLC_ML_PARENT_UNKNOWN) {
+        NSString *currentItemMrl = currentInputItem.MRL;
+
+        NSUInteger itemIndexInDisplayedCollection = [self->_displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
+            VLCMediaLibraryMediaItem *mediaItem = (VLCMediaLibraryMediaItem *)element;
+            return [mediaItem.inputItem.MRL isEqualToString:currentItemMrl];
+        }];
+
+        if (itemIndexInDisplayedCollection != NSNotFound) {
+            [_songsTableView scrollRowToVisible:itemIndexInDisplayedCollection];
+        }
+    }
+}
+
 - (void)libraryModelUpdated:(NSNotification *)aNotification
 {
     if(self.libraryModel == nil) {


=====================================
modules/gui/macosx/playlist/VLCPlaylistModel.m
=====================================
@@ -56,6 +56,10 @@
 
 - (VLCPlaylistItem *)playlistItemAtIndex:(NSInteger)index
 {
+    if (index < 0 || index > _playlistArray.count) {
+        return nil;
+    }
+    
     return _playlistArray[index];
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/203fb201da9c44bf5d68c937a071f5a8f25fda2f...2cc6bcc880620f6d469c6ee82747b6edabec098b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/203fb201da9c44bf5d68c937a071f5a8f25fda2f...2cc6bcc880620f6d469c6ee82747b6edabec098b
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