vlc | branch: master | Felix Paul Kühne <fe...@feepk.net> | Sun Jun 30 14:14:26 
2019 +0200| [a094528a49d9bd7e515a81d9b89fb3845eb71995] | committer: Felix Paul 
Kühne

macosx/image view: allow setting images with URLs and placeholders

This downloads and allocates the image on a background thread without blocking 
the UI.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a094528a49d9bd7e515a81d9b89fb3845eb71995
---

 modules/gui/macosx/views/VLCImageView.h |  2 ++
 modules/gui/macosx/views/VLCImageView.m | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/modules/gui/macosx/views/VLCImageView.h 
b/modules/gui/macosx/views/VLCImageView.h
index 46e73f95c1..4008d299da 100644
--- a/modules/gui/macosx/views/VLCImageView.h
+++ b/modules/gui/macosx/views/VLCImageView.h
@@ -42,4 +42,6 @@ typedef NS_ENUM(NSInteger, VLCImageViewContentGravity) {
 @property (readwrite, retain, nonatomic, nullable) NSImage *image;
 @property (readwrite) VLCImageViewContentGravity contentGravity;
 
+- (void)setImageURL:(NSURL * _Nonnull)url placeholderImage:(NSImage * 
_Nullable)image;
+
 @end
diff --git a/modules/gui/macosx/views/VLCImageView.m 
b/modules/gui/macosx/views/VLCImageView.m
index c0015df9d5..bd4184cbfd 100644
--- a/modules/gui/macosx/views/VLCImageView.m
+++ b/modules/gui/macosx/views/VLCImageView.m
@@ -121,4 +121,15 @@
     [self setupBorderColor];
 }
 
+- (void)setImageURL:(NSURL * _Nonnull)artworkURL placeholderImage:(NSImage * 
_Nullable)image
+{
+    [self setImage:image];
+    
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 
0), ^{
+        NSImage *downloadedImage = [[NSImage alloc] 
initWithContentsOfURL:artworkURL];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self setImage:downloadedImage];
+        });
+    });
+}
+
 @end

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to