[vlc-commits] macosx: implement playlist reset and dynamic updating
Felix Paul Kühne
git at videolan.org
Thu Jan 31 17:58:39 CET 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Thu Jan 31 17:17:48 2019 +0100| [19684ab6a4d227640399bd3134401b1896204f9a] | committer: Felix Paul Kühne
macosx: implement playlist reset and dynamic updating
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=19684ab6a4d227640399bd3134401b1896204f9a
---
modules/gui/macosx/UI/VLCPlaylistTableCellView.xib | 1 +
modules/gui/macosx/VLCPlaylistController.h | 5 ++++
modules/gui/macosx/VLCPlaylistController.m | 34 ++++++++++++++++++++--
modules/gui/macosx/VLCPlaylistDataSource.m | 2 +-
modules/gui/macosx/VLCPlaylistItem.h | 1 +
modules/gui/macosx/VLCPlaylistItem.m | 29 ++++++++++--------
modules/gui/macosx/VLCPlaylistModel.h | 3 ++
modules/gui/macosx/VLCPlaylistModel.m | 17 +++++++++++
8 files changed, 76 insertions(+), 16 deletions(-)
diff --git a/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib b/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib
index aaab3b6169..eab65dcab2 100644
--- a/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib
+++ b/modules/gui/macosx/UI/VLCPlaylistTableCellView.xib
@@ -44,6 +44,7 @@
<constraint firstItem="ohB-P0-nCv" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="mGo-gc-dR6"/>
<constraint firstItem="Hnm-OH-KKY" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="owl-FT-tZX"/>
<constraint firstItem="Hnm-OH-KKY" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="vEf-1U-gh4"/>
+ <constraint firstItem="3Ha-ZH-fa9" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="ohB-P0-nCv" secondAttribute="trailing" constant="10" id="wQv-VX-Hhb"/>
</constraints>
<connections>
<outlet property="durationTextField" destination="3Ha-ZH-fa9" id="vbh-oE-Afj"/>
diff --git a/modules/gui/macosx/VLCPlaylistController.h b/modules/gui/macosx/VLCPlaylistController.h
index a2fdd85966..ced07666d6 100644
--- a/modules/gui/macosx/VLCPlaylistController.h
+++ b/modules/gui/macosx/VLCPlaylistController.h
@@ -48,6 +48,11 @@ NS_ASSUME_NONNULL_BEGIN
@property (readwrite, assign) VLCPlaylistDataSource *playlistDataSource;
/**
+ * Index of the current playlist item
+ */
+ at property (readonly) size_t currentPlaylistIndex;
+
+/**
* indicates whether there is a previous item in the list the user could go back to
*/
@property (readonly) BOOL hasPreviousPlaylistItem;
diff --git a/modules/gui/macosx/VLCPlaylistController.m b/modules/gui/macosx/VLCPlaylistController.m
index f5e632e925..e4aa8e3736 100644
--- a/modules/gui/macosx/VLCPlaylistController.m
+++ b/modules/gui/macosx/VLCPlaylistController.m
@@ -32,9 +32,11 @@
vlc_playlist_listener_id *_playlistListenerID;
}
+- (void)playlistResetWithItems:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems;
- (void)playlistAdded:(vlc_playlist_item_t *const *)items atIndex:(size_t)insertionIndex count:(size_t)numberOfItems;
- (void)playlistRemovedItemsAtIndex:(size_t)index count:(size_t)numberOfItems;
- (void)currentPlaylistItemChanged:(ssize_t)index;
+- (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems;
@end
@@ -48,6 +50,8 @@ cb_playlist_items_reset(vlc_playlist_t *playlist,
void *p_data)
{
NSLog(@"%s: numberOfItems %zu", __func__, numberOfItems);
+ VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data;
+ [playlistController playlistResetWithItems:items count:numberOfItems];
}
static void
@@ -75,12 +79,14 @@ cb_playlist_items_removed(vlc_playlist_t *playlist,
static void
cb_playlist_items_updated(vlc_playlist_t *playlist,
- size_t index,
+ size_t firstUpdatedIndex,
vlc_playlist_item_t *const items[],
- size_t len,
+ size_t numberOfUpdatedItems,
void *p_data)
{
- NSLog(@"%s: index: %zu len: %zu", __func__, index, len);
+ NSLog(@"%s: index: %zu len: %zu", __func__, firstUpdatedIndex, numberOfUpdatedItems);
+ VLCPlaylistController *playlistController = (__bridge VLCPlaylistController *)p_data;
+ [playlistController playlistUpdatedForIndex:firstUpdatedIndex items:items count:numberOfUpdatedItems];
}
static void
@@ -159,6 +165,17 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
#pragma mark - callback forwarders
+- (void)playlistResetWithItems:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems
+{
+ NSLog(@"%s", __func__);
+
+ for (size_t i = 0; i < numberOfItems; i++) {
+ [_playlistModel addItem:items[i]];
+ }
+
+ [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
+}
+
- (void)playlistAdded:(vlc_playlist_item_t *const *)items atIndex:(size_t)insertionIndex count:(size_t)numberOfItems
{
NSLog(@"%s", __func__);
@@ -184,6 +201,17 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
- (void)currentPlaylistItemChanged:(ssize_t)index
{
+ _currentPlaylistIndex = index;
+ [_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
+}
+
+- (void)playlistUpdatedForIndex:(size_t)firstUpdatedIndex items:(vlc_playlist_item_t *const *)items count:(size_t)numberOfItems
+{
+ NSLog(@"%s", __func__);
+ VLC_UNUSED(items);
+ for (size_t i = firstUpdatedIndex; i < firstUpdatedIndex + numberOfItems; i++) {
+ [_playlistModel updateItemAtIndex:i];
+ }
[_playlistDataSource performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
}
diff --git a/modules/gui/macosx/VLCPlaylistDataSource.m b/modules/gui/macosx/VLCPlaylistDataSource.m
index 05e7df8a55..cedb6060ae 100644
--- a/modules/gui/macosx/VLCPlaylistDataSource.m
+++ b/modules/gui/macosx/VLCPlaylistDataSource.m
@@ -77,7 +77,7 @@ static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier";
}
cellView.mediaTitleTextField.stringValue = item.title;
- cellView.durationTextField.stringValue = [NSString stringWithTime:item.duration];
+ cellView.durationTextField.stringValue = [NSString stringWithTimeFromTicks:item.duration];
cellView.mediaImageView.image = [NSImage imageNamed: @"noart.png"];
// TODO: show more data if available
diff --git a/modules/gui/macosx/VLCPlaylistItem.h b/modules/gui/macosx/VLCPlaylistItem.h
index 8168b1dc27..b1b0f28ffb 100644
--- a/modules/gui/macosx/VLCPlaylistItem.h
+++ b/modules/gui/macosx/VLCPlaylistItem.h
@@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (readwrite, retain, nullable) NSString *artworkURLString;
- (instancetype)initWithPlaylistItem:(vlc_playlist_item_t *)p_item;
+- (void)updateRepresentation;
@end
diff --git a/modules/gui/macosx/VLCPlaylistItem.m b/modules/gui/macosx/VLCPlaylistItem.m
index 52da3b1c5f..c881709bef 100644
--- a/modules/gui/macosx/VLCPlaylistItem.m
+++ b/modules/gui/macosx/VLCPlaylistItem.m
@@ -32,24 +32,29 @@
self = [super init];
if (self) {
_playlistItem = p_item;
- input_item_t *p_media = vlc_playlist_item_GetMedia(p_item);
- vlc_mutex_lock(&p_media->lock);
- _title = toNSStr(p_media->psz_name);
- _duration = p_media->i_duration;
-
- if (p_media->p_meta) {
- _artistName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Artist));
- _albumName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Album));
- _artworkURLString = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_ArtworkURL));
- }
- vlc_mutex_unlock(&p_media->lock);
+ [self updateRepresentation];
}
return self;
}
- (NSString *)description
{
- return [NSString stringWithFormat:@"item %p, title: %@", &_playlistItem, _title];
+ return [NSString stringWithFormat:@"item %p, title: %@ duration %lli", &_playlistItem, _title, _duration];
+}
+
+- (void)updateRepresentation
+{
+ input_item_t *p_media = vlc_playlist_item_GetMedia(_playlistItem);
+ vlc_mutex_lock(&p_media->lock);
+ _title = toNSStr(p_media->psz_name);
+ _duration = p_media->i_duration;
+
+ if (p_media->p_meta) {
+ _artistName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Artist));
+ _albumName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Album));
+ _artworkURLString = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_ArtworkURL));
+ }
+ vlc_mutex_unlock(&p_media->lock);
}
- (NSString *)path
diff --git a/modules/gui/macosx/VLCPlaylistModel.h b/modules/gui/macosx/VLCPlaylistModel.h
index d5697739e0..855d622b86 100644
--- a/modules/gui/macosx/VLCPlaylistModel.h
+++ b/modules/gui/macosx/VLCPlaylistModel.h
@@ -33,9 +33,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (readwrite, assign) VLCPlaylistController *playlistController;
@property (readonly) size_t numberOfPlaylistItems;
+- (void)dropExistingData;
- (VLCPlaylistItem *)playlistItemAtIndex:(NSInteger)index;
+- (void)addItem:(vlc_playlist_item_t *)item;
- (void)addItem:(vlc_playlist_item_t *)item atIndex:(size_t)index;
- (void)removeItemAtIndex:(size_t)index;
+- (void)updateItemAtIndex:(size_t)index;
@end
diff --git a/modules/gui/macosx/VLCPlaylistModel.m b/modules/gui/macosx/VLCPlaylistModel.m
index 795f691e15..2183b76f8d 100644
--- a/modules/gui/macosx/VLCPlaylistModel.m
+++ b/modules/gui/macosx/VLCPlaylistModel.m
@@ -53,11 +53,22 @@
return ret;
}
+- (void)dropExistingData
+{
+ [_playlistArray removeAllObjects];
+}
+
- (VLCPlaylistItem *)playlistItemAtIndex:(NSInteger)index
{
return _playlistArray[index];
}
+- (void)addItem:(vlc_playlist_item_t *)item
+{
+ VLCPlaylistItem *playlistItem = [[VLCPlaylistItem alloc] initWithPlaylistItem:item];
+ [_playlistArray addObject:playlistItem];
+}
+
- (void)addItem:(vlc_playlist_item_t *)item atIndex:(size_t)index
{
VLCPlaylistItem *playlistItem = [[VLCPlaylistItem alloc] initWithPlaylistItem:item];
@@ -69,4 +80,10 @@
[_playlistArray removeObjectAtIndex:index];
}
+- (void)updateItemAtIndex:(size_t)index
+{
+ VLCPlaylistItem *item = _playlistArray[index];
+ [item updateRepresentation];
+}
+
@end
More information about the vlc-commits
mailing list