swift学习之旅---SJVideoPlayer库

27 篇文章 0 订阅

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文件找到想要的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值