• Stars
    star
    2,347
  • Rank 18,790 (Top 0.4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 6 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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群吧)

赞助

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

More Repositories

1

SJAttributesFactory

Simplify operation NSAttributedString, make writing easier. Attributes String Editing Factory. iOS 富文本编辑, 让代码更清晰. 文本编辑, 高度计算, 正则匹配等待... 简便操作, 让你爽到爆!
Objective-C
373
star
2

SJFullscreenPopGesture

Fullscreen pop gesture. OC&Swift. It is very suitable for the application of the video player. Support `cocoapods`. 只需`pod`即可自带全屏返回手势. 支持pod. 支持OC&Swift.
Objective-C
281
star
3

SJMediaCacheServer

A HTTP Media Caching Framework. It can cache FILE or HLS media. 音视频边播边缓存框架, 支持 HLS(m3u8) 和 FILE(mp4, mp3等).
Objective-C
219
star
4

SJBaseVideoPlayer

video player. rotation, volume, brightness, rate, play, pause, stop, seekToTime, present.
Objective-C
117
star
5

SJSQLite3

DatabaseMapping. database mapping. Automatically create tables based on the model. 数据库模型映射. 自动建表, 自动更新表. 增删改查一句话搞定. 支持模糊查询, 各种插入和更新, 支持存储模型数组. pod SJSQLite3
Objective-C
114
star
6

SJSlider

滑块视图
Objective-C
94
star
7

SJLabel

一个支持匹配点击的 label . a label, Supports attributes text matching clicks.
Objective-C
51
star
8

SJPageViewController

A container view controller that manages navigation between pages of content, where each page is managed by a child view controller.
Objective-C
42
star
9

SJRouter

iOS Router
Objective-C
35
star
10

SJRecordVideo

record video and export. 短视频录制. 自由定制录制时间. 支持横竖屏录制&暂停&对焦&本地选取.
Objective-C
32
star
11

SJLoadingView

loading view.
Ruby
21
star
12

SJObserverHelper

SJObserverHelper, 观察者模式, 只需要观察即可, 不需要移除.
Objective-C
16
star
13

SJMP3Player

mp3 player, play while downloading. support set rate, and local cache. mp3播放器, 边下载边播放, 支持调速, 控制台操作.
Objective-C
15
star
14

LWZComponents

一些组件库
Objective-C
14
star
15

SJM3U8Downloader

Objective-C
14
star
16

SJBorderLineView

视图 或上或下或左或右 绘制一条线
Objective-C
6
star
17

SJAudioPlayer

A MP3 audio player. AVAudioEngine & AVAudioPlayerNode
Objective-C
6
star
18

SJMP3PlayWhileDownloadingProject

MP3歌曲边下载边播放, 支持调速, 控制台操作.
Objective-C
3
star
19

SJTransitionAnimator

Modal自定义转场动画
Objective-C
3
star
20

SJReciteWords

recite words
Objective-C
2
star
21

SJFrameLayout

Objective-C
2
star
22

SJUIKit

备份
Objective-C
2
star
23

iOS-Locks

Objective-C
1
star
24

SJPlaybackListController

SJVideoPlayer 播放列表控制器
Objective-C
1
star
25

PodIJKPlayer

Objective-C
1
star
26

SJSQLGenerator

最近在复习SQL语句, 为加深效果以及后期防止遗忘, 便使用OC写了一个便利构造SQL语句的库.
Objective-C
1
star