Giter Site home page Giter Site logo

changsanjiang / sjvideoplayer Goto Github PK

View Code? Open in Web Editor NEW
2.4K 38.0 471.0 368.87 MB

iOS VideoPlayer MediaPlayer video player media player 短视频播放器 可接入 ijkplayer aliplayer alivodplayer plplayer

License: MIT License

Objective-C 99.29% Ruby 0.50% C 0.21%
videoplayer video-player generate-gif avplayer player

sjvideoplayer's Introduction

readme

Build Status Version Platform License

安装

pod 'SJVideoPlayer'

项目配置旋转

  • step 1: 前往Targets -> General -> Device Orientation -> 选择 Portrait;

  • step 2: 前往AppDelegate, 导入头文件#import "SJRotationManager.h", 在application:supportedInterfaceOrientationsForWindow:中返回[SJRotationManager supportedInterfaceOrientationsForWindow:window];

#import "SJRotationManager.h"

@implementation AppDelegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [SJRotationManager supportedInterfaceOrientationsForWindow:window];
}
@end

/// swift
/// class AppDelegate: UIResponder, UIApplicationDelegate {
///     func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> /// UIInterfaceOrientationMask {
///         return window.supportedInterfaceOrientations(window)
///     }
/// }
  • step 3: 以下分类在项目中随便找个地方, 复制进去即可;
@implementation UIViewController (RotationConfiguration)
- (BOOL)shouldAutorotate { 
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
@end


@implementation UITabBarController (RotationConfiguration)
- (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 (RotationConfiguration)
- (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
  • setup 4: iOS 13.0 之后, 需在自己的vc中实现shouldAutorotate, 并返回NO.
@interface YourPlayerViewController ()
@property (nonatomic, strong) SJVideoPlayer *player;
@end

@implementation YourPlayerViewController 
- (BOOL)shouldAutorotate { 
    return NO;
} 

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [_player vc_viewDidAppear]; 
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated]; 
    [_player vc_viewWillDisappear];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_player vc_viewDidDisappear]; 
}
@end

快速开始

  1. 导入头文件
#import <SJVideoPlayer/SJVideoPlayer.h>
  1. 添加player属性
@interface ViewController ()
@property (nonatomic, strong, readonly) SJVideoPlayer *player;
@end
  1. 创建player对象
- (void)viewDidLoad {
    [super viewDidLoad];
    
    _player = SJVideoPlayer.player;
    [self.view addSubview:_player.view];
    [_player.view mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        } else {
            make.top.offset(20);
        }
        make.left.right.offset(0);
        make.height.equalTo(self.player.view.mas_width).multipliedBy(9/16.0);
    }];
}

- (BOOL)shouldAutorotate {
    return NO;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [_player vc_viewDidAppear];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_player vc_viewWillDisappear];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_player vc_viewDidDisappear];
}
  1. 通过URL进行播放
SJVideoPlayerURLAsset *asset = [SJVideoPlayerURLAsset.alloc initWithURL:_media.URL];
_player.URLAsset = asset;

Author

Email: [email protected]

QQGroup: 610197491 (iOS 开发 2)

QQGroup: 930508201 (iOS 开发)(这个群满员了, 请加2群吧)

赞助

如果对您有所帮助,欢迎您的赞赏

sjvideoplayer's People

Contributors

anharismail avatar changsanjiang avatar joooenn avatar jozdee avatar shafujiu avatar summerzhuqiong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sjvideoplayer's Issues

播放器缺少标题啊

一般播放器都会在左上角用来显示视频名称的,但是好像并不支持,能不能加入一下

新界面继续播放,进度条在走,但是视频画面是卡住不动的

_player.URLAsset = [[SJVideoPlayerURLAsset alloc] initWithOtherAsset:_asset playModel:[SJPlayModel new]];

今天在使用过程中遇到了一个问题,新界面继续播放Demo,点击next进入下一个VC,进度条在走,但是视频是卡住不动的。劳烦作者有空看下?

另外为作者开源精神点赞。

Not Playing video Display black screen

i'm simply use following code but it display black screen.

SJVideoPlayer *videoPlayer = [SJVideoPlayer player];
videoPlayer.view.frame = CGRectMake(0, 20, 200, 200 * 9/16.0);
[self.view addSubview:videoPlayer.view];
videoPlayer.URLAsset = [[SJVideoPlayerURLAsset alloc] initWithURL:[NSURL URLWithString:@"http://yxfile.idealsee.com/9f6f64aca98f90b91d260555d3b41b97_mp4.mp4"]];
[videoPlayer play];

In log display following output:-

SJBaseVideoPlayer<0x111dc82d0>.SJVideoPlayerPlayStatus.Prepare
VideoPlayerDemo[1093:534379] CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
"m_Limit" = "m_LimitAll";
"r_Attributes" = 1;
sync = syna;
}
VideoPlayerDemo[1093:534344] 91 - -[SJVideoPlayer dealloc]
VideoPlayerDemo[1093:534344] 58 - -[SJAVMediaPlaybackController dealloc]
VideoPlayerDemo[1093:534344] 42 - -[SJAVMediaPlayAsset dealloc]

Change video background color

How to change video background color ?

I'm use this code to change background color but player background color is show black.

self.SJplayer?.view.backgroundColor = .white

你好, 有个小问题.

你好, 暂停的时候, 当我设置rate后, 播放按钮还是显示暂停, 但是视频已经开始播放了.

关于禁止滑动返回的问题

你好,关于禁止系统滑动返回手势的问题,

  • (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ( self.navigationController.topViewController.sj_DisableGestures ||
    [[self.navigationController valueForKey:@"_isTransitioning"] boolValue] ||
    [self.navigationController.topViewController.sj_considerWebView canGoBack] ) return NO;
    else if ( self.navigationController.childViewControllers.count <= 1 ) return NO;
    else if ( [self.navigationController.childViewControllers.lastObject isKindOfClass:[UINavigationController class]] ) return NO;
    // return YES;
    return self.navigationController.interactivePopGestureRecognizer.enabled;

}
我将yes改成了系统默认的返回值是不是会好一点,今天这个坑了我一天啊,怎么都禁止不了,假如你有好的方法 请提供给我 ,谢谢

Crash

void setAVMediaPlayAsset(id media, SJAVMediaPlayAsset *_Nullable playAsset) {
objc_setAssociatedObject(media, kSJAVMediaPlayAsset, playAsset, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -- Thread 3: EXC_BAD_ACCESS (code=1, address=0x0)
}

Application crashes here..

Touch on VideoPlayer

Hi there,
I add video player to viewcontroller have tableview, when i click full screen, i can't touch on video player. just touch on my viewcontroller. Please tell me why?
My ViewController in a PageViewController , and PageViewController in a TabBarController.
Thanks

cocoapods导入报错

SJOrentationObserver.h

  • (instancetype)initWithTarget:(__weak UIView *)view container:(__weak UIView *)targetSuperview;
    报错 Cannot create __weak reference because the current deployment target does not support weak references

pod install报错,使用pod update 仍然报错

[!] Error installing SJBaseVideoPlayer
[!] /usr/bin/git clone https://github.com/changsanjiang/SJBaseVideoPlayer.git /var/folders/h3/wkw1c8wd4jn2ytqwb_rptg5h0000gn/T/d20180808-2907-1r9ge0v --template= --single-branch --depth 1 --branch v1.3.2

Cloning into '/var/folders/h3/wkw1c8wd4jn2ytqwb_rptg5h0000gn/T/d20180808-2907-1r9ge0v'...
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

编译报错

_videoPlayer.URLAsset.isMP3
提示Property 'isMP3' not found on object of type 'SJVideoPlayerURLAsse不存在这个属性。。

Unable to install Pod file

[!] Error installing SJBaseVideoPlayer
[!] /usr/bin/git clone https://gitee.com/changsanjiang/SJBaseVideoPlayer.git /var/folders/ky/gx0qy0q106v_pz025qh4qvmh0000gn/T/d20181130-9861-k3qjoq --template= --single-branch --depth 1 --branch v1.5.0

Cloning into '/var/folders/ky/gx0qy0q106v_pz025qh4qvmh0000gn/T/d20181130-9861-k3qjoq'...
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

我输出总是遇到这个Log,是怎么回事?

(lldb) po imageView.size
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here
declared here with type 'SJDisappearType'
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here
declared here with type 'SJDisappearType'
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here
declared here with type 'SJDisappearType'
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here
declared here with type 'SJDisappearType'
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here
declared here with type 'SJDisappearType'
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here
warning: property access result unused - getters should not be used for side effects
declared here with type 'SJDisappearType'
error: instance method 'disappearType' has incompatible result types in different translation units ('SJViewDisappearType' vs. 'SJDisappearType')
instance method 'disappearType' also declared here

video buffering issue

If video buffering is state called.

I'm work like insta story app. story in video is buffering is pause.

==== here my code == . this code only for check is ready for play

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

    if object as AnyObject? === self.SJplayer {
        if keyPath == "playStatus" {

            if self.SJplayer?.playStatus == .readyToPlay {

Thanks in advance

rtsp/rtmp support?

hello. that's great lib.
Then thanks for fully explained readme.
Does it support for rtsp/rtmp?

利用scrollView实现滚动切换效果时,多个界面会存在同时播放的情况。

利用scrollView实现滚动切换效果,而非pageViewController,控制视图声明周期方法不会执行,所以就会有多个界面在播放视频。
解决办法:
在确定切换了界面时,发出通知,收到通知后将播放器stopAndFadeout即可。
根据页码索引的改变确实界面是否切换。

给遇到同样问题的朋友,提供个思路。

感谢作者牛逼的框架!

旋转后状态栏隐藏了

在xs max 模拟器上测试,旋转后状态栏隐藏了。控制层显示时也不显示,Demo也是如此。
UIStatusBarStyle->UIStatusBarStyleLightContent

第一次单击屏幕,topView和bottomView会闪一下。第二次单击才正常

1、开始播放视频之后,第一次单击屏幕,topView和bottomView会闪一下。第二次单击才正常显示和自动消失
2、播放高清网络视频,有两处异常:
①经常会出现转圈并暂停播放,双击后,视频可以正常继续播放(网络状态良好)
②转圈圈情况下,点击剪辑,完成后取消,圈停止转动,并悬浮在屏幕上。

SJVideoPlayerSettings的placeholder是UIImage

SJVideoPlayerSettings的placeholder是UIImage,所以不能设置UIImageView的contentMode属性,这样会导致如果展位图不够全屏,会被强制拉伸到全屏。而视频播放的时候,是居中,上下留白(黑)的。想要实现的是 占位图是视屏的第一帧,占位图完全贴合播放的真实大小,这样就会看起来流畅些。若占位是UIImageview或者吧contentMode暴露出来就好了。会更加灵活

Full Screen

Video full screen, how i scale it to small in my viewcontroller ?

视频详情页面画面卡顿但是有声音

当我在列表页面,播放一段时间,或者快进一段时间的时候,进入详情页面,它会接着上一个时间段播放,这时候有一个问题,画面卡顿,音频在走,是不是应该有一个菊花,等缓冲那个点再播放。

Volume and Brightness Setting

Hi there,
Please tell me how to disable Volume and Brightness setting at tableview viewctroller. I can't understand example.
Thanks.

播放状态未改变

在播放视频时退到后台再返回app的时候,播放界面的状态已经变成暂停状态,但是播放按钮的状态还是播放,没有变成暂停。
这个问题是在2.1.0.2版本中发现的

Installing SJLabel时报错

Installing SJLabel (1.1.0)

[!] Error installing SJLabel
[!] /usr/bin/git clone https://github.com/changsanjiang/SJLabel.git /var/folders/ht/r89947ls459fq5d1jz203s5h0000gn/T/d20180226-4771-ut4plr --template= --single-branch --depth 1 --branch v1.1.0

Cloning into '/var/folders/ht/r89947ls459fq5d1jz203s5h0000gn/T/d20180226-4771-ut4plr'...
warning: Could not find remote branch v1.1.0 to clone.
fatal: Remote branch v1.1.0 not found in upstream origin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.