6 Star 35 Fork 12

changsanjiang / SJVideoPlayer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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: changsanjiang@gmail.com

QQGroup: 610197491 (iOS 开发 2)

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

赞助

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

MIT License Copyright (c) 2017 changsanjiang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

功能齐全的视频播放器 展开 收起
Objective-C 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Objective-C
1
https://gitee.com/changsanjiang/SJVideoPlayer.git
git@gitee.com:changsanjiang/SJVideoPlayer.git
changsanjiang
SJVideoPlayer
SJVideoPlayer
master

搜索帮助