mirror of
https://code.videolan.org/videolan/vlc
synced 2024-09-04 09:11:33 +02:00
macosx: Add guard for out of bounds indexes provided as arguments for VLCPlaylistModel's playlistItemAtIndex
Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
This commit is contained in:
parent
14655e1c31
commit
2cc6bcc880
@ -44,6 +44,8 @@
|
||||
#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"
|
||||
@ -112,29 +114,42 @@ static NSString *VLCLibraryYearSortDescriptorKey = @"VLCLibraryYearSortDescripto
|
||||
|
||||
- (void)playlistItemChanged:(NSNotification *)aNotification
|
||||
{
|
||||
// HACK: If we ask for the currently playing item too quickly
|
||||
// we will get the previous item from the playlist controller...
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
|
||||
VLCInputItem *currentPlayingItem = VLCMain.sharedInstance.playlistController.currentlyPlayingInputItem;
|
||||
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 (!currentPlayingItem) {
|
||||
NSLog(@"Current playing type is invalid.");
|
||||
return;
|
||||
// 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];
|
||||
}
|
||||
|
||||
if (self->_currentParentType == VLC_ML_PARENT_UNKNOWN) {
|
||||
NSString *currentItemMrl = currentPlayingItem.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) {
|
||||
[self->_songsTableView scrollRowToVisible:itemIndexInDisplayedCollection];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)libraryModelUpdated:(NSNotification *)aNotification
|
||||
|
@ -56,6 +56,10 @@
|
||||
|
||||
- (VLCPlaylistItem *)playlistItemAtIndex:(NSInteger)index
|
||||
{
|
||||
if (index < 0 || index > _playlistArray.count) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return _playlistArray[index];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user