| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- //
- // WebRtcPlayerViewController.m
- // 双子星云手机
- //
- // Created by xd h on 2024/4/29.
- //
- #import "WebRtcPlayerViewController.h"
- #import "AppDelegate.h"
- @interface WebRtcPlayerViewController ()
- @property (nonatomic, assign) BOOL canRate;
- @property (nonatomic, assign) BOOL isLan;
- @end
- @implementation WebRtcPlayerViewController {
- //ARDFileCaptureController *_fileCaptureController NS_AVAILABLE_IOS(10);
- webRtcVideoCallView *_videoCallView;
- NSURL *_url;
- NSString* _roomName;
- NSInteger _direct;
- NSInteger _fmt;
- NSInteger _vsize;
- NSInteger _fps;
- NSInteger _bitrate;
- }
- @synthesize delegate=_delegate;
- - (instancetype)initForRoom:(NSURL *)url
- roomName:(NSString*)roomName
- direct:(NSInteger)direct
- fmt:(NSInteger)fmt
- vsize:(NSInteger)vsize
- fps:(NSInteger)fps
- bitrate:(NSInteger)bitrate
- delegate:(id<WebRtcPlayerViewControllerDelegate>)delegate {
- if (self = [super init]) {
- self->_url=url;
- self->_roomName=roomName;
- self->_direct=direct;
- self->_fmt=fmt;
- self->_vsize=vsize;
- self->_fps=fps;
- self->_bitrate=bitrate;
- self.delegate=delegate;
- [self customLoadView];
- [self addNSNotification];
- }
- return self;
- }
- - (void)customLoadView {
- _canRate = NO;
- _isLan = NO;
- AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
- app.isInPlayer = YES;
- _videoCallView = [[webRtcVideoCallView alloc] initForRoom:_url
- roomName:_roomName
- direct:_direct
- fmt:_fmt
- vsize:_vsize
- fps:_fps
- bitrate:_bitrate
- delegate:self];
- self.view = _videoCallView;
-
- //[self.view addSubview:_videoCallView];
- // _videoCallView.frame = CGRectMake(0, 0, SCREEN_W, SCREEN_H);
-
- // [_videoCallView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(0);
- // make.right.mas_equalTo(0);
- // make.top.mas_equalTo(100);
- // make.bottom.mas_equalTo(200);
- // }];
- }
- - (void)videoCallViewDidHangup:(webRtcVideoCallView *)view{
- [_delegate viewControllerDidFinish:self];
- }
- -(void)onFrameResolutionChangedFromPeerName:(NSString*)peerName videoWidth:(int)videoWidth videoHeight:(int)videoHeight rotation:(int)rotation {
- HLog(@"横屏状态:%d",rotation);
-
-
- if (rotation == 0) {
- self.isLan = NO;
- [horizontalScreenTool setCurScreenIsHorizontaltype:NO];
- } else {
- self.isLan = YES;
- [horizontalScreenTool setCurScreenIsHorizontaltype:YES];
- }
-
- if (@available(iOS 16,*)){
- [self setNeedsUpdateOfSupportedInterfaceOrientations];
- }
- }
- #pragma mark - 屏幕旋转相关
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- return UIInterfaceOrientationPortrait;
- }
- - (BOOL)shouldAutorotate {
- if (_canRate)/*画面发现变化 状态变为YES*/{
- _canRate = NO;/*关键点 只能旋转一次*/
- AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
- app.allowAutoRotate = NO;
- return YES;
- }
- //是否允许转屏
- return NO;/*平时禁止*/
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- if (@available(iOS 16,*)){
- if (_isLan){
- return UIInterfaceOrientationMaskLandscapeLeft;
- }
- return UIInterfaceOrientationMaskPortrait;
- }
- return UIInterfaceOrientationMaskAll;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- self.toolBar.hidden = YES;
- self.navigationBar.hidden = YES;
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- // 屏幕常亮
- [UIApplication sharedApplication].idleTimerDisabled = YES;
- [[UIApplication sharedApplication] setStatusBarHidden:YES];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
- app.isInPlayer = NO;
- app.allowAutoRotate = NO;
- [horizontalScreenTool setCurScreenIsHorizontaltype:NO];
- [super viewWillDisappear:animated];
-
- // 屏幕常亮
- [UIApplication sharedApplication].idleTimerDisabled = NO;
- [[UIApplication sharedApplication] setStatusBarHidden:NO];
- }
- - (void)addNSNotification
- {
-
- [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(void *)[AVAudioSession sharedInstance]];
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
- if(context == (__bridge void *)[AVAudioSession sharedInstance])
- {
- float newValue = [[change objectForKey:@"new"] floatValue];
- float oldValue = [[change objectForKey:@"old"] floatValue];
- if (newValue > oldValue)
- {
- HLog(@"\n-----音量增加");
- [_videoCallView volumeUp];
- }
- else
- {
- HLog(@"\n-----音量降低");
- [_videoCallView volumeDown];
- }
- }
- }
- @end
|