Skip to content

Commit 2f3bb53

Browse files
author
yuzheng
committed
TZVideoPreviewCell增强,支持用NSURL播放视频(需配合TZImagePreviewController库);发布3.1.7
1 parent 26810d0 commit 2f3bb53

9 files changed

Lines changed: 56 additions & 30 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ A:不要去拿PHImageFileURLKey,没用的,只有通过Photos框架才能
124124

125125
## 六. Release Notes 最近更新
126126

127-
3.1.6 批量获取图片时加入队列控制,尝试优化大批量选择图片时CPU和内存占用过高的问题(仍然危险,maxImagesCount谨慎设置过大...)
127+
3.1.7 批量获取图片时加入队列控制,尝试优化大批量选择图片时CPU和内存占用过高的问题(仍然危险,maxImagesCount谨慎设置过大...)
128128
3.1.5 相册内无照片时给出提示,修复快速滑动时内存一直增加的问题
129129
3.1.3 适配阿拉伯等语言下从右往左布局的特性
130130
3.0.8 新增gifImagePlayBlock允许使用FLAnimatedImage等替换内部的GIF播放方案

TZImagePickerController.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Pod::Spec.new do |s|
22
s.name = "TZImagePickerController"
3-
s.version = "3.1.6"
3+
s.version = "3.1.7"
44
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
55
s.homepage = "https://github.com/banchichen/TZImagePickerController"
66
s.license = "MIT"
77
s.author = { "banchichen" => "tanzhenios@foxmail.com" }
88
s.platform = :ios
99
s.ios.deployment_target = "8.0"
10-
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "3.1.6" }
10+
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "3.1.7" }
1111
s.requires_arc = true
1212
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,bundle}"
1313
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"

TZImagePickerController/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.1.6</string>
18+
<string>3.1.7</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

TZImagePickerController/TZImagePickerController/TZImagePickerController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by 谭真 on 15/12/24.
66
// Copyright © 2015年 谭真. All rights reserved.
7-
// version 3.1.6 - 2018.12.20
7+
// version 3.1.7 - 2019.01.04
88
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
99

1010
/*

TZImagePickerController/TZImagePickerController/TZImagePickerController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by 谭真 on 15/12/24.
66
// Copyright © 2015年 谭真. All rights reserved.
7-
// version 3.1.6 - 2018.12.20
7+
// version 3.1.7 - 2019.01.04
88
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
99

1010
#import "TZImagePickerController.h"

TZImagePickerController/TZImagePickerController/TZPhotoPreviewCell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
@property (strong, nonatomic) AVPlayerLayer *playerLayer;
5959
@property (strong, nonatomic) UIButton *playButton;
6060
@property (strong, nonatomic) UIImage *cover;
61+
@property (nonatomic, strong) NSURL *videoURL;
6162
- (void)pausePlayerAndShowNaviBar;
6263
@end
6364

TZImagePickerController/TZImagePickerController/TZPhotoPreviewCell.m

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ - (void)refreshImageContainerViewCenter {
355355
@implementation TZVideoPreviewCell
356356

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

361361
- (void)configPlayButton {
@@ -374,6 +374,11 @@ - (void)setModel:(TZAssetModel *)model {
374374
[self configMoviePlayer];
375375
}
376376

377+
- (void)setVideoURL:(NSURL *)videoURL {
378+
_videoURL = videoURL;
379+
[self configMoviePlayer];
380+
}
381+
377382
- (void)configMoviePlayer {
378383
if (_player) {
379384
[_playerLayer removeFromSuperlayer];
@@ -382,20 +387,29 @@ - (void)configMoviePlayer {
382387
_player = nil;
383388
}
384389

385-
[[TZImageManager manager] getPhotoWithAsset:self.model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
386-
self->_cover = photo;
387-
}];
388-
[[TZImageManager manager] getVideoWithAsset:self.model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) {
389-
dispatch_async(dispatch_get_main_queue(), ^{
390-
self->_player = [AVPlayer playerWithPlayerItem:playerItem];
391-
self->_playerLayer = [AVPlayerLayer playerLayerWithPlayer:self->_player];
392-
self->_playerLayer.backgroundColor = [UIColor blackColor].CGColor;
393-
self->_playerLayer.frame = self.bounds;
394-
[self.layer addSublayer:self->_playerLayer];
395-
[self configPlayButton];
396-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlayerAndShowNaviBar) name:AVPlayerItemDidPlayToEndTimeNotification object:self->_player.currentItem];
397-
});
398-
}];
390+
if (self.model && self.model.asset) {
391+
[[TZImageManager manager] getPhotoWithAsset:self.model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
392+
self.cover = photo;
393+
}];
394+
[[TZImageManager manager] getVideoWithAsset:self.model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) {
395+
dispatch_async(dispatch_get_main_queue(), ^{
396+
[self configPlayerWithItem:playerItem];
397+
});
398+
}];
399+
} else {
400+
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:self.videoURL];
401+
[self configPlayerWithItem:playerItem];
402+
}
403+
}
404+
405+
- (void)configPlayerWithItem:(AVPlayerItem *)playerItem {
406+
self.player = [AVPlayer playerWithPlayerItem:playerItem];
407+
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
408+
self.playerLayer.backgroundColor = [UIColor blackColor].CGColor;
409+
self.playerLayer.frame = self.bounds;
410+
[self.layer addSublayer:self.playerLayer];
411+
[self configPlayButton];
412+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlayerAndShowNaviBar) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];
399413
}
400414

401415
- (void)layoutSubviews {
@@ -405,7 +419,17 @@ - (void)layoutSubviews {
405419
}
406420

407421
- (void)photoPreviewCollectionViewDidScroll {
408-
[self pausePlayerAndShowNaviBar];
422+
if (_player && _player.rate != 0.0) {
423+
[self pausePlayerAndShowNaviBar];
424+
}
425+
}
426+
427+
#pragma mark - Notification
428+
429+
- (void)appWillResignActiveNotification {
430+
if (_player && _player.rate != 0.0) {
431+
[self pausePlayerAndShowNaviBar];
432+
}
409433
}
410434

411435
#pragma mark - Click Event
@@ -427,12 +451,10 @@ - (void)playButtonClick {
427451
}
428452

429453
- (void)pausePlayerAndShowNaviBar {
430-
if (_player.rate != 0.0) {
431-
[_player pause];
432-
[_playButton setImage:[UIImage tz_imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal];
433-
if (self.singleTapGestureBlock) {
434-
self.singleTapGestureBlock();
435-
}
454+
[_player pause];
455+
[_playButton setImage:[UIImage tz_imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal];
456+
if (self.singleTapGestureBlock) {
457+
self.singleTapGestureBlock();
436458
}
437459
}
438460

TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(
502502
if ([cell isKindOfClass:[TZPhotoPreviewCell class]]) {
503503
[(TZPhotoPreviewCell *)cell recoverSubviews];
504504
} else if ([cell isKindOfClass:[TZVideoPreviewCell class]]) {
505-
[(TZVideoPreviewCell *)cell pausePlayerAndShowNaviBar];
505+
TZVideoPreviewCell *videoCell = (TZVideoPreviewCell *)cell;
506+
if (videoCell.player && videoCell.player.rate != 0.0) {
507+
[videoCell pausePlayerAndShowNaviBar];
508+
}
506509
}
507510
}
508511

TZImagePickerControllerFramework/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.1.6</string>
18+
<string>3.1.7</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

0 commit comments

Comments
 (0)