Skip to content

Commit

Permalink
⚒增加滚动播放位置的API
Browse files Browse the repository at this point in the history
  • Loading branch information
renzifeng committed May 25, 2020
1 parent 1f2425e commit 07c1e77
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ - (void)requestData {

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
if (scrollToTop) {
[self.player playTheIndexPath:indexPath scrollPosition:ZFPlayerScrollViewScrollPositionCenteredVertically animated:YES];
} else {
[self.player playTheIndexPath:indexPath];
}
ZFTableData *data = self.dataSource[indexPath.row];
[self.controlView showTitle:data.title
coverURLString:data.thumbnail_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void)viewDidLoad {
/// 停止的时候找出最合适的播放
self.player.zf_scrollViewDidEndScrollingCallback = ^(NSIndexPath * _Nonnull indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
};
}

Expand All @@ -91,7 +91,7 @@ - (void)viewDidAppear:(BOOL)animated {
@weakify(self)
[self.collectionView zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}];
}

Expand Down Expand Up @@ -140,7 +140,7 @@ - (void)playTheIndex:(NSInteger)index {
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
[self.collectionView zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}];
/// 如果是最后一行,去请求新数据
if (index == self.dataSource.count-1) {
Expand All @@ -152,8 +152,8 @@ - (void)playTheIndex:(NSInteger)index {
}

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
[self.player playTheIndexPath:indexPath];
[self.controlView resetControlView];
ZFTableData *data = self.dataSource[indexPath.row];
UIViewContentMode imageMode;
Expand Down Expand Up @@ -204,7 +204,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}

- (UICollectionView *)collectionView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (void)viewDidLoad {
/// 停止的时候找出最合适的播放
self.player.zf_scrollViewDidEndScrollingCallback = ^(NSIndexPath * _Nonnull indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
};
}

Expand All @@ -90,7 +90,7 @@ - (void)viewDidAppear:(BOOL)animated {
@weakify(self)
[self.collectionView zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}];
}

Expand Down Expand Up @@ -136,8 +136,8 @@ - (void)requestData {
}

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
[self.player playTheIndexPath:indexPath];
ZFTableData *data = self.dataSource[indexPath.row];
[self.controlView showTitle:data.title
coverURLString:data.thumbnail_url
Expand Down Expand Up @@ -178,13 +178,13 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
@weakify(self)
cell.playBlock = ^(UIButton *sender) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
};
return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}

- (UICollectionView *)collectionView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ - (void)viewDidLoad {
self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskLandscape;
[self.player enterFullScreen:YES animated:NO];
playerManager.assetURL = [NSURL URLWithString:@"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4"];

self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
kAPPDelegate.allowOrentitaionRotation = isFullScreen;
};
}

- (void)viewWillAppear:(BOOL)animated {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ - (void)zf_playTheVideoAtIndexPath:(NSIndexPath *)indexPath {

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
if (scrollToTop) {
[self.player playTheIndexPath:indexPath scrollPosition:ZFPlayerScrollViewScrollPositionCenteredVertically animated:YES];
} else {
[self.player playTheIndexPath:indexPath];
}
ZFTableViewCellLayout *layout = self.dataSource[indexPath.row];
[self.controlView showTitle:layout.data.title
coverURLString:layout.data.thumbnail_url
Expand Down
14 changes: 7 additions & 7 deletions Example/ZFPlayer/TableView/Controller/ZFDouYinViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (void)viewDidLoad {
self.player.assetURLs = self.urls;
[self.tableView reloadData];
}
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
};
}

Expand All @@ -105,7 +105,7 @@ - (void)loadNewData {
/// 找到可以播放的视频并播放
[self.tableView zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}];
});
}
Expand Down Expand Up @@ -134,7 +134,7 @@ - (void)playTheIndex:(NSInteger)index {
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
[self.tableView zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
@strongify(self)
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}];
/// 如果是最后一行,去请求新数据
if (index == self.dataSource.count-1) {
Expand Down Expand Up @@ -197,13 +197,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}

#pragma mark - ZFTableViewCellDelegate

- (void)zf_playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}

#pragma mark - private method
Expand All @@ -213,8 +213,8 @@ - (void)backClick:(UIButton *)sender {
}

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
[self.player playTheIndexPath:indexPath];
[self.controlView resetControlView];
ZFTableData *data = self.dataSource[indexPath.row];
UIViewContentMode imageMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ - (void)zf_playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
if (scrollToTop) {
/// 自定义滑动动画时间
[self.tableView zf_scrollToRowAtIndexPath:indexPath animateWithDuration:0.8 completionHandler:^{
[self.player playTheIndexPath:indexPath];
}];
[self.player playTheIndexPath:indexPath scrollPosition:ZFPlayerScrollViewScrollPositionTop animated:YES];
} else {
[self.player playTheIndexPath:indexPath];
}
Expand Down
6 changes: 5 additions & 1 deletion Example/ZFPlayer/TableView/Controller/ZFMixViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ - (void)zf_playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
NSInteger index = (indexPath.row-1)/3;
ZFTableViewCellLayout *layout = self.dataSource[index];
[self.player playTheIndexPath:indexPath assetURL:[NSURL URLWithString:layout.data.video_url] scrollToTop:scrollToTop];
if (scrollToTop) {
[self.player playTheIndexPath:indexPath assetURL:[NSURL URLWithString:layout.data.video_url] scrollPosition:ZFPlayerScrollViewScrollPositionTop animated:YES];
} else {
[self.player playTheIndexPath:indexPath assetURL:[NSURL URLWithString:layout.data.video_url]];
}
[self.controlView showTitle:layout.data.title
coverURLString:layout.data.thumbnail_url
fullScreenMode:layout.isVerticalVideo?ZFFullScreenModePortrait:ZFFullScreenModeLandscape];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
/// 如果没有播放,则点击进详情页会自动播放
if (!self.player.currentPlayerManager.isPlaying) {
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}
/// 到详情页
ZFPlayerDetailViewController *detailVC = [ZFPlayerDetailViewController new];
Expand Down Expand Up @@ -194,14 +194,14 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
#pragma mark - ZFTableViewCellDelegate

- (void)zf_playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
[self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
[self playTheVideoAtIndexPath:indexPath];
}

#pragma mark - private method

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath {
[self.player playTheIndexPath:indexPath];
ZFTableViewCellLayout *layout = self.dataSource[indexPath.row];
[self.controlView showTitle:layout.data.title
coverURLString:layout.data.thumbnail_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ - (void)zf_playTheVideoAtIndexPath:(NSIndexPath *)indexPath {

/// play the video
- (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
if (scrollToTop) {
[self.player playTheIndexPath:indexPath scrollPosition:ZFPlayerScrollViewScrollPositionCenteredVertically animated:YES];
} else {
[self.player playTheIndexPath:indexPath];
}
ZFTableViewCellLayout *layout = self.dataSource[indexPath.row];
[self.controlView showTitle:layout.data.title
coverURLString:layout.data.thumbnail_url
Expand Down
29 changes: 10 additions & 19 deletions ZFPlayer/Classes/ControlView/UIImageView+ZFCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ + (NSString *)zf_keyForRequest:(NSURLRequest *)request;

@implementation NSString (md5)

+ (NSString *)zf_keyForRequest:(NSURLRequest *)request{
+ (NSString *)zf_keyForRequest:(NSURLRequest *)request {
return request.URL.absoluteString;
}

Expand Down Expand Up @@ -159,8 +159,7 @@ - (void)zf_clearDiskCaches {
if ([[NSFileManager defaultManager] fileExistsAtPath:directoryPath isDirectory:nil]) {
dispatch_queue_t ioQueue = dispatch_queue_create("com.hackemist.SDWebImageCache", DISPATCH_QUEUE_SERIAL);
dispatch_async(ioQueue, ^{
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtPath:directoryPath error:&error];
[[NSFileManager defaultManager] removeItemAtPath:directoryPath error:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:directoryPath
withIntermediateDirectories:YES
attributes:nil
Expand Down Expand Up @@ -227,47 +226,39 @@ @implementation UIImageView (ZFCache)

#pragma mark - getter

- (ZFImageBlock)completion
{
- (ZFImageBlock)completion {
return objc_getAssociatedObject(self, _cmd);
}

- (ZFImageDownloader *)imageDownloader
{
- (ZFImageDownloader *)imageDownloader {
return objc_getAssociatedObject(self, _cmd);
}

- (NSUInteger)attemptToReloadTimesForFailedURL
{
- (NSUInteger)attemptToReloadTimesForFailedURL {
NSUInteger count = [objc_getAssociatedObject(self, _cmd) integerValue];
if (count == 0) { count = 2; }
return count;
}

- (BOOL)shouldAutoClipImageToViewSize
{
- (BOOL)shouldAutoClipImageToViewSize {
return [objc_getAssociatedObject(self, _cmd) boolValue];
}

#pragma mark - setter

- (void)setCompletion:(ZFImageBlock)completion
{
- (void)setCompletion:(ZFImageBlock)completion {
objc_setAssociatedObject(self, @selector(completion), completion, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void)setImageDownloader:(ZFImageDownloader *)imageDownloader
{
- (void)setImageDownloader:(ZFImageDownloader *)imageDownloader {
objc_setAssociatedObject(self, @selector(imageDownloader), imageDownloader, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)setAttemptToReloadTimesForFailedURL:(NSUInteger)attemptToReloadTimesForFailedURL
{
- (void)setAttemptToReloadTimesForFailedURL:(NSUInteger)attemptToReloadTimesForFailedURL {
objc_setAssociatedObject(self, @selector(attemptToReloadTimesForFailedURL), @(attemptToReloadTimesForFailedURL), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)setShouldAutoClipImageToViewSize:(BOOL)shouldAutoClipImageToViewSize
{
- (void)setShouldAutoClipImageToViewSize:(BOOL)shouldAutoClipImageToViewSize {
objc_setAssociatedObject(self, @selector(shouldAutoClipImageToViewSize), @(shouldAutoClipImageToViewSize), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

Expand Down
Loading

0 comments on commit 07c1e77

Please sign in to comment.