Skip to content

Commit

Permalink
TZVideoPreviewCell增强,支持用NSURL播放视频(需配合TZImagePreviewController库);发布3.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
banchichen committed Jan 4, 2019
1 parent 26810d0 commit 2f3bb53
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ A:不要去拿PHImageFileURLKey,没用的,只有通过Photos框架才能

## 六. Release Notes 最近更新

3.1.6 批量获取图片时加入队列控制,尝试优化大批量选择图片时CPU和内存占用过高的问题(仍然危险,maxImagesCount谨慎设置过大...)
3.1.7 批量获取图片时加入队列控制,尝试优化大批量选择图片时CPU和内存占用过高的问题(仍然危险,maxImagesCount谨慎设置过大...)
3.1.5 相册内无照片时给出提示,修复快速滑动时内存一直增加的问题
3.1.3 适配阿拉伯等语言下从右往左布局的特性
3.0.8 新增gifImagePlayBlock允许使用FLAnimatedImage等替换内部的GIF播放方案
Expand Down
4 changes: 2 additions & 2 deletions TZImagePickerController.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "TZImagePickerController"
s.version = "3.1.6"
s.version = "3.1.7"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT"
s.author = { "banchichen" => "[email protected]" }
s.platform = :ios
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "3.1.6" }
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "3.1.7" }
s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
Expand Down
2 changes: 1 addition & 1 deletion TZImagePickerController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.1.6</string>
<string>3.1.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// version 3.1.6 - 2018.12.20
// version 3.1.7 - 2019.01.04
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// version 3.1.6 - 2018.12.20
// version 3.1.7 - 2019.01.04
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController

#import "TZImagePickerController.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
@property (strong, nonatomic) AVPlayerLayer *playerLayer;
@property (strong, nonatomic) UIButton *playButton;
@property (strong, nonatomic) UIImage *cover;
@property (nonatomic, strong) NSURL *videoURL;
- (void)pausePlayerAndShowNaviBar;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ - (void)refreshImageContainerViewCenter {
@implementation TZVideoPreviewCell

- (void)configSubviews {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlayerAndShowNaviBar) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActiveNotification) name:UIApplicationWillResignActiveNotification object:nil];
}

- (void)configPlayButton {
Expand All @@ -374,6 +374,11 @@ - (void)setModel:(TZAssetModel *)model {
[self configMoviePlayer];
}

- (void)setVideoURL:(NSURL *)videoURL {
_videoURL = videoURL;
[self configMoviePlayer];
}

- (void)configMoviePlayer {
if (_player) {
[_playerLayer removeFromSuperlayer];
Expand All @@ -382,20 +387,29 @@ - (void)configMoviePlayer {
_player = nil;
}

[[TZImageManager manager] getPhotoWithAsset:self.model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
self->_cover = photo;
}];
[[TZImageManager manager] getVideoWithAsset:self.model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{
self->_player = [AVPlayer playerWithPlayerItem:playerItem];
self->_playerLayer = [AVPlayerLayer playerLayerWithPlayer:self->_player];
self->_playerLayer.backgroundColor = [UIColor blackColor].CGColor;
self->_playerLayer.frame = self.bounds;
[self.layer addSublayer:self->_playerLayer];
[self configPlayButton];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlayerAndShowNaviBar) name:AVPlayerItemDidPlayToEndTimeNotification object:self->_player.currentItem];
});
}];
if (self.model && self.model.asset) {
[[TZImageManager manager] getPhotoWithAsset:self.model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
self.cover = photo;
}];
[[TZImageManager manager] getVideoWithAsset:self.model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{
[self configPlayerWithItem:playerItem];
});
}];
} else {
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:self.videoURL];
[self configPlayerWithItem:playerItem];
}
}

- (void)configPlayerWithItem:(AVPlayerItem *)playerItem {
self.player = [AVPlayer playerWithPlayerItem:playerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.backgroundColor = [UIColor blackColor].CGColor;
self.playerLayer.frame = self.bounds;
[self.layer addSublayer:self.playerLayer];
[self configPlayButton];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlayerAndShowNaviBar) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];
}

- (void)layoutSubviews {
Expand All @@ -405,7 +419,17 @@ - (void)layoutSubviews {
}

- (void)photoPreviewCollectionViewDidScroll {
[self pausePlayerAndShowNaviBar];
if (_player && _player.rate != 0.0) {
[self pausePlayerAndShowNaviBar];
}
}

#pragma mark - Notification

- (void)appWillResignActiveNotification {
if (_player && _player.rate != 0.0) {
[self pausePlayerAndShowNaviBar];
}
}

#pragma mark - Click Event
Expand All @@ -427,12 +451,10 @@ - (void)playButtonClick {
}

- (void)pausePlayerAndShowNaviBar {
if (_player.rate != 0.0) {
[_player pause];
[_playButton setImage:[UIImage tz_imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal];
if (self.singleTapGestureBlock) {
self.singleTapGestureBlock();
}
[_player pause];
[_playButton setImage:[UIImage tz_imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal];
if (self.singleTapGestureBlock) {
self.singleTapGestureBlock();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(
if ([cell isKindOfClass:[TZPhotoPreviewCell class]]) {
[(TZPhotoPreviewCell *)cell recoverSubviews];
} else if ([cell isKindOfClass:[TZVideoPreviewCell class]]) {
[(TZVideoPreviewCell *)cell pausePlayerAndShowNaviBar];
TZVideoPreviewCell *videoCell = (TZVideoPreviewCell *)cell;
if (videoCell.player && videoCell.player.rate != 0.0) {
[videoCell pausePlayerAndShowNaviBar];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion TZImagePickerControllerFramework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.1.6</string>
<string>3.1.7</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 2f3bb53

Please sign in to comment.