SJVideoPlayer(swift)
https://github.com/changsanjiang/SJVideoPlayer 非常优秀的库,而且里面有大量的demo来供我们学习,给作者加颗星不过分吧
610197491 库作者的官方群,如果遇到奇葩的问题找江哥解决
pod ‘SJVideoPlayer’
哔哩哔哩的ijkplayer在M1电脑跑太糟心了,真机不能跑,报的错误都是关于arm64的,网上我找不到教程,而且作者也好像不管这个库的更新了,到目前为止最近一次更新为5个月前,发了issues也没人解答
如果哪个大哥也是用M1 ijkplayer的请教教小弟
sjvideoplayer如果不设置是默认为avplayer为内核播放的,并且支持cell播放,自定义播放器样式,全屏、iOS14功能的画中画也支持,给作者大大的点赞
配置环境
pod install教程不说了
在真机iphone6的真机上旋转出现异常 可以看官方给出的答案 https://github.com/changsanjiang/SJVideoPlayer/wiki/点击旋转卡死或者旋转出现异常%3F
直接用作者的源代码
//
// UIViewController+SJConfigureRotation.m
// SJVideoPlayerDemo
//
// Created by 畅三江 on 2019/10/20.
// Copyright ? 2019 畅三江. All rights reserved.
//
#import "UIViewController+SJConfigureRotation.h"
// step 3:
@implementation UIViewController (SJConfigureRotation)
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@end
@implementation UITabBarController (SJConfigureRotation)
- (UIViewController *)sj_topViewController {
if ( self.selectedIndex == NSNotFound )
return self.viewControllers.firstObject;
return self.selectedViewController;
}
- (BOOL)shouldAutorotate {
return [[self sj_topViewController] shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [[self sj_topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self sj_topViewController] preferredInterfaceOrientationForPresentation];
}
@end
@implementation UINavigationController (SJConfigureRotation)
- (BOOL)shouldAutorotate {
return self.topViewController.shouldAutorotate;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.topViewController.supportedInterfaceOrientations;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.topViewController.preferredInterfaceOrientationForPresentation;
}
- (nullable UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
- (nullable UIViewController *)childViewControllerForStatusBarHidden {
return self.topViewController;
}
@end
想要在cell里的cover图(UIImageView )播放 后面的coverImage 就是他的子类 就要继承SJPlayModelPlayerSuperview
import UIKit
import SJVideoPlayer
class PlayerSuperImageView: UIImageView,SJPlayModelPlayerSuperview {
}
请求图片网络图片就按照正常的来就行,sdwebimage yywebimage都可以,因为他是继承UIImageview
搞个点击事件
func setGesture() {
coverImage.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapAction))
coverImage.addGestureRecognizer(tap)
}
@objc func tapAction() {
tapGoAction?()
}
cell.tapGoAction = { [weak self] in
self?.cellPlay(indexPath)
}
var player: SJVideoPlayer = SJVideoPlayer()
func cellPlay(_ indexPath: IndexPath) {
let model = videoModel[indexPath.row]
if let url = URL(string: model.videoUrl ?? "") {
player.urlAsset = SJVideoPlayerURLAsset.init(url:url, playModel: SJPlayModel.init(tableView: playerContainView, indexPath: indexPath))
player.urlAsset?.title = model.title
}
}
这样就能在cell的imageview里播放,简单的一批
想要修改播放器,画中画可以在https://github.com/changsanjiang/SJVideoPlayer 里的demo文件找到想要的
|