Skip to end of metadata
Go to start of metadata

Для отображения потока во весь экран рекомендуется использовать RTCMTLVideoView, поскольку RTCEAGLVideoView искажает пропорции при изменении размеров

code

    id<MTLDevice> remoteDevice;
#ifdef __aarch64__
    remoteDevice = MTLCreateSystemDefaultDevice();
    if (remoteDevice) {
        RTCMTLVideoView *remoteView = [[RTCMTLVideoView alloc] init];
        remoteView.delegate = self;
        remoteView.videoContentMode = UIViewContentModeScaleAspectFit;
        _remoteDisplay = remoteView;
        _remoteDisplay.backgroundColor = [UIColor blackColor];
        UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullscreenButton:)];
        singleFingerTap.numberOfTapsRequired = 2;
        [_remoteDisplay addGestureRecognizer:singleFingerTap];
    }
#endif
    if (!_remoteDisplay) {
        RTCEAGLVideoView *remoteView = [[RTCEAGLVideoView alloc] init];
        remoteView.delegate = self;
        _remoteDisplay = remoteView;
    }
    _remoteDisplay.translatesAutoresizingMaskIntoConstraints = NO;

Для переключения в полный экран задаем элементу, в котором проигрывается поток, размеры экрана в качестве максимальных

code

        [_remoteDisplay.widthAnchor constraintEqualToConstant: [[UIScreen mainScreen] bounds].size.width].active = YES;
        [_remoteDisplay.heightAnchor constraintEqualToConstant:[[UIScreen mainScreen] bounds].size.height].active = YES;
        [_remoteDisplay removeFromSuperview];
        [_scrollView addSubview:_remoteDisplay];

Для выхода из полноэкранного режима задаем элементу, в котором проигрывается поток, размеры контейнера на экране

code

        [_remoteDisplay removeFromSuperview];
        [_videoContainer addSubview:_remoteDisplay];
        
        NSLayoutConstraint *constraint =[NSLayoutConstraint constraintWithItem:_remoteDisplay attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_remoteDisplay attribute:NSLayoutAttributeHeight multiplier:640.0/480.0 constant:0];
        [_remoteDisplay addConstraint:constraint];

        constraint =[NSLayoutConstraint constraintWithItem:_remoteDisplay attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:_videoContainer attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
        [_videoContainer addConstraint:constraint];

        [_videoContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[remoteDisplay]|" options:NSLayoutFormatAlignAllTop metrics:@{} views:@{@"remoteDisplay": _remoteDisplay}]];

        [_videoContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[remoteDisplay]|" options:0 metrics:@{} views:@{@"remoteDisplay": _remoteDisplay}]];
    
  • No labels