Skip to content

Commit

Permalink
macosx: Work around issue where playlist controller will return previ…
Browse files Browse the repository at this point in the history
…ously playing item when called immediately after notification of item changed

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra authored and fkuehne committed Dec 24, 2022
1 parent 5b408d8 commit 14655e1
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,29 @@ - (instancetype)init

- (void)playlistItemChanged:(NSNotification *)aNotification
{
if (_currentParentType == VLC_ML_PARENT_UNKNOWN) {
// 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;

NSUInteger itemIndexInDisplayedCollection = [_displayedCollection indexOfObjectPassingTest:^BOOL(id element, NSUInteger idx, BOOL *stop) {
VLCMediaLibraryMediaItem *mediaItem = (VLCMediaLibraryMediaItem *)element;
return [mediaItem.inputItem.MRL isEqualToString:currentPlayingItem.MRL];
}];
if (!currentPlayingItem) {
NSLog(@"Current playing type is invalid.");
return;
}

[_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
Expand Down

0 comments on commit 14655e1

Please sign in to comment.