Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在AVPlayer中默认以横向模式播放视频?_Ios_Objective C_Iphone_Avplayer - Fatal编程技术网

Ios 如何在AVPlayer中默认以横向模式播放视频?

Ios 如何在AVPlayer中默认以横向模式播放视频?,ios,objective-c,iphone,avplayer,Ios,Objective C,Iphone,Avplayer,我现在想在横向模式下播放视频,在纵向模式下播放。我希望在调用playMethod时,它应该仅以横向模式打开视频。创建从AvPlayServiceController继承的自定义类,并使用该类而不是基本AvPlayServiceController - (void)playMethod { NSURL *url = [[NSURL alloc] initWithString:@"https://www.rmp- streaming.com/media///bbb-360p.mp4

我现在想在横向模式下播放视频,在纵向模式下播放。我希望在调用playMethod时,它应该仅以横向模式打开视频。

创建从AvPlayServiceController继承的自定义类,并使用该类而不是基本AvPlayServiceController

- (void)playMethod
{
    NSURL *url = [[NSURL alloc] initWithString:@"https://www.rmp- 
    streaming.com/media///bbb-360p.mp4"];
    player = [AVPlayer playerWithURL:url];
    controller = [[AVPlayerViewController alloc] init];
    [self addChildViewController:controller];
    [self.view addSubview:controller.view];

    controller.view.frame = CGRectMake(15,50,345,300);
    controller.player = player;
    controller.showsPlaybackControls = YES;
    player.closedCaptionDisplayEnabled = NO;

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 addTarget:self
                action:@selector(backMethod)
      forControlEvents:UIControlEventTouchUpInside];
    [button1 setTitle:@"Back" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
     button1.frame = CGRectMake(50.0, CGRectGetMinY(controller.view.frame)+10, 160.0, 40.0);
    button1.tag = 1001;
    [self.view addSubview:button1];
    [controller.view  bringSubviewToFront:button1];
    [player pause];
    [player play];
    }

您必须强制更改设备的方向。因为现在你的设备处于横向,所以视频总是播放横向。可能重复的请检查此链接
import AVKit

class CustomAVPlayerViewController: AVPlayerViewController {

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscapeLeft
    }
}