iOS VideoPlayer MediaPlayer video player media player 短视频播放器 可接入 ijkplayer aliplayer alivodplayer plplayer
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)
/// }
/// }
@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
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
#import <SJVideoPlayer/SJVideoPlayer.h>
player
属性@interface ViewController ()
@property (nonatomic, strong, readonly) SJVideoPlayer *player;
@end
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];
}
SJVideoPlayerURLAsset *asset = [SJVideoPlayerURLAsset.alloc initWithURL:_media.URL];
_player.URLAsset = asset;
Email: [email protected]
QQGroup: 610197491 (iOS 开发 2)
QQGroup: 930508201 (iOS 开发)(这个群满员了, 请加2群吧)
如果对您有所帮助,欢迎您的赞赏