|
|
|
@ -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 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; |
|
|
|
} |
|
|
|
|
|
|
|
if (!currentPlayingItem) { |
|
|
|
NSLog(@"Current playing type is invalid."); |
|
|
|
return; |
|
|
|
} |
|
|
|
VLCPlaylistItem *currentPlayingItem = [playlistModel playlistItemAtIndex:currentPlaylistIndex]; |
|
|
|
if (!currentPlayingItem) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (self->_currentParentType == VLC_ML_PARENT_UNKNOWN) { |
|
|
|
NSString *currentItemMrl = currentPlayingItem.MRL; |
|
|
|
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]; |
|
|
|
}]; |
|
|
|
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]; |
|
|
|
} |
|
|
|
if (itemIndexInDisplayedCollection != NSNotFound) { |
|
|
|
[_songsTableView scrollRowToVisible:itemIndexInDisplayedCollection]; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
- (void)libraryModelUpdated:(NSNotification *)aNotification |
|
|
|
|