You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2018/03/12 03:15:33 UTC

[1/3] incubator-weex git commit: + [iOS] add WXVideoComponent "poster" attribute.

Repository: incubator-weex
Updated Branches:
  refs/heads/master 5b901c007 -> 939bc5454


+ [iOS] add WXVideoComponent "poster" attribute.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/946bcec8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/946bcec8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/946bcec8

Branch: refs/heads/master
Commit: 946bcec8fbbfbb4d3bd1767e3a8d55a759576017
Parents: a59ddfe
Author: 徐有阳 <xu...@corp.netease.com>
Authored: Wed Mar 7 10:59:44 2018 +0800
Committer: 徐有阳 <xu...@corp.netease.com>
Committed: Wed Mar 7 10:59:44 2018 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXVideoComponent.h        |  2 +
 .../Sources/Component/WXVideoComponent.m        | 65 ++++++++++++++++++++
 2 files changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/946bcec8/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.h
index 4703a7a..bf9d908 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.h
@@ -30,8 +30,10 @@ typedef NS_ENUM(NSInteger, WXPlaybackState) {
 @interface WXVideoView : UIView
 
 @property (nonatomic, copy) void (^playbackStateChanged)(WXPlaybackState state);
+@property (nonatomic, copy) void (^posterClickHandle)(void);
 
 - (void) setURL:(NSURL*)URL;
+- (void) setPosterURL:(NSURL *)posterURL;
 
 - (void) play;
 - (void) pause;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/946bcec8/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
index d9aadc4..42c61e2 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
@@ -21,6 +21,7 @@
 #import "WXHandlerFactory.h"
 #import "WXURLRewriteProtocol.h"
 #import "WXSDKEngine.h"
+#import "WXImgLoaderProtocol.h"
 
 #import <AVFoundation/AVPlayer.h>
 #import <AVKit/AVPlayerViewController.h>
@@ -41,6 +42,9 @@
 @property (nonatomic, strong) UIViewController* playerViewController;
 @property (nonatomic, strong) AVPlayerItem* playerItem;
 @property (nonatomic, strong) WXSDKInstance* weexSDKInstance;
+@property (nonatomic, strong) UIImageView *posterImageView;
+@property (nonatomic, strong) id<WXImageOperationProtocol> imageOperation;
+@property (nonatomic, assign) BOOL playerDidPlayed;
 
 @end
 
@@ -85,6 +89,13 @@
         }
         
         [self addSubview:_playerViewController.view];
+        
+        _posterImageView = [[UIImageView alloc] init];
+        _posterImageView.userInteractionEnabled = YES;
+        [_posterImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(posterTapHandler)]];
+        _posterImageView.hidden = YES;
+        [self addSubview:_posterImageView];
+        [self bringSubviewToFront:_posterImageView];
     }
     return self;
 }
@@ -147,6 +158,7 @@
     videoFrame.origin.x = 0;
     videoFrame.origin.y = 0;
     [_playerViewController.view setFrame:videoFrame];
+    [_posterImageView setFrame:videoFrame];
 }
 
 - (void)setURL:(NSURL *)URL
@@ -188,6 +200,24 @@
     }
 }
 
+- (void)setPosterURL:(NSURL *)posterURL {
+    if (!posterURL) {
+        return;
+    }
+    
+    [self cancelImage];
+    __weak typeof(self) weakSelf = self;
+    weakSelf.imageOperation = [[self imageLoader] downloadImageWithURL:posterURL.absoluteString imageFrame:self.posterImageView.frame userInfo:nil completed:^(UIImage *image, NSError *error, BOOL finished) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            __strong typeof(self) strongSelf = weakSelf;
+            if (!error) {
+                strongSelf.posterImageView.image = image;
+                strongSelf.posterImageView.hidden = strongSelf.playerDidPlayed;
+            }
+        });
+    }];
+}
+
 - (void)playFinish
 {
     if (_playbackStateChanged)
@@ -203,6 +233,7 @@
 
 - (void)play
 {
+    _posterImageView.hidden = YES;
     if ([self greater8SysVer]) {
         AVPlayerViewController *AVVC = (AVPlayerViewController*)_playerViewController;
 
@@ -224,12 +255,35 @@
     }
 }
 
+- (void)posterTapHandler {
+    if (self.posterClickHandle) {
+        self.posterClickHandle();
+    }
+}
+
+- (id<WXImgLoaderProtocol>)imageLoader
+{
+    static id<WXImgLoaderProtocol> imageLoader;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        imageLoader = [WXHandlerFactory handlerForProtocol:@protocol(WXImgLoaderProtocol)];
+    });
+    return imageLoader;
+}
+
+- (void)cancelImage
+{
+    [_imageOperation cancel];
+    _imageOperation = nil;
+}
+
 @end
 
 @interface WXVideoComponent()
 
 @property (nonatomic, weak) WXVideoView *videoView;
 @property (nonatomic, strong) NSURL *videoURL;
+@property (nonatomic, strong) NSURL *posterURL;
 @property (nonatomic) BOOL autoPlay;
 @property (nonatomic) BOOL playStatus;
 
@@ -252,6 +306,9 @@
         if ([attributes[@"playStatus"] compare:@"pause" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
             _playStatus = false;
         }
+        if (attributes[@"poster"]) {
+            _posterURL = [NSURL URLWithString: attributes[@"poster"]];
+        }
     }
     return self;
 }
@@ -268,6 +325,7 @@
 {
     _videoView = (WXVideoView *)self.view;
     [_videoView setURL:_videoURL];
+    [_videoView setPosterURL:_posterURL];
     if (_playStatus) {
         [_videoView play];
     } else {
@@ -277,6 +335,9 @@
         [_videoView play];
     }
     __weak __typeof__(self) weakSelf = self;
+    _videoView.posterClickHandle = ^{
+        [weakSelf.videoView play];
+    };
     _videoView.playbackStateChanged = ^(WXPlaybackState state) {
         NSString *eventType = nil;
         switch (state) {
@@ -319,6 +380,10 @@
         _playStatus = false;
         [_videoView pause];
     }
+    if (attributes[@"poster"]) {
+        _posterURL = [NSURL URLWithString: attributes[@"poster"]];
+        [_videoView setPosterURL:_posterURL];
+    }
 }
 
 @end


[3/3] incubator-weex git commit: Merge branch 'ios-feature-videoPoster' of https://github.com/xuyouyang/incubator-weex into merge-pull-request-master

Posted by ac...@apache.org.
Merge branch 'ios-feature-videoPoster' of https://github.com/xuyouyang/incubator-weex into merge-pull-request-master


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/939bc545
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/939bc545
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/939bc545

Branch: refs/heads/master
Commit: 939bc545439cceb542b85a6f4135c8e649223283
Parents: 5b901c0 b0e4455
Author: acton393 <zh...@gmail.com>
Authored: Mon Mar 12 11:15:10 2018 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Mon Mar 12 11:15:10 2018 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXVideoComponent.h        |  2 +
 .../Sources/Component/WXVideoComponent.m        | 69 ++++++++++++++++++++
 2 files changed, 71 insertions(+)
----------------------------------------------------------------------



[2/3] incubator-weex git commit: [WEEX-241][iOS] add WXVideoComponent "poster" attribute. Lazy load UIImageView property.

Posted by ac...@apache.org.
[WEEX-241][iOS] add WXVideoComponent "poster" attribute.
Lazy load UIImageView property.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b0e44554
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b0e44554
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b0e44554

Branch: refs/heads/master
Commit: b0e44554f107ee1d3456c08d655ab98ae3d3fdb1
Parents: 946bcec
Author: xuyouyang <xu...@corp.netease.com>
Authored: Thu Mar 8 13:41:48 2018 +0800
Committer: xuyouyang <xu...@corp.netease.com>
Committed: Thu Mar 8 13:41:48 2018 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXVideoComponent.m        | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b0e44554/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
index 42c61e2..82b2be5 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXVideoComponent.m
@@ -89,13 +89,6 @@
         }
         
         [self addSubview:_playerViewController.view];
-        
-        _posterImageView = [[UIImageView alloc] init];
-        _posterImageView.userInteractionEnabled = YES;
-        [_posterImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(posterTapHandler)]];
-        _posterImageView.hidden = YES;
-        [self addSubview:_posterImageView];
-        [self bringSubviewToFront:_posterImageView];
     }
     return self;
 }
@@ -158,7 +151,6 @@
     videoFrame.origin.x = 0;
     videoFrame.origin.y = 0;
     [_playerViewController.view setFrame:videoFrame];
-    [_posterImageView setFrame:videoFrame];
 }
 
 - (void)setURL:(NSURL *)URL
@@ -261,6 +253,18 @@
     }
 }
 
+- (UIImageView *)posterImageView {
+    if (!_posterImageView) {
+        _posterImageView = [[UIImageView alloc] initWithFrame:self.bounds];
+        _posterImageView.userInteractionEnabled = YES;
+        [_posterImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(posterTapHandler)]];
+        _posterImageView.hidden = YES;
+        [self addSubview:_posterImageView];
+        [self bringSubviewToFront:_posterImageView];
+    }
+    return _posterImageView;
+}
+
 - (id<WXImgLoaderProtocol>)imageLoader
 {
     static id<WXImgLoaderProtocol> imageLoader;