iOS VIMVideoPlayerView 无法加载 vimeo 视频
iOS VIMVideoPlayerView can't load vimeo videos
我正在 Objective C 中制作一个 iOS 应用程序,它必须使用 vimeo 网址加载视频。我想使用视频播放器,我用了这个:https://github.com/vimeo/VIMVideoPlayer。
我按照自述说明进行操作,但是我无法阅读 vimeo 视频,出现错误:
Video player Status Failed: error = Error
Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open"
UserInfo=0x7f9c5d17b8c0 {NSUnderlyingError=0x7f9c5d176910 "The
operation couldn’t be completed. (OSStatus error -12847.)",
NSLocalizedFailureReason=This media format is not supported.,
NSLocalizedDescription=Cannot Open}
这是我的代码:
-(void)viewDidLoad
{
[super viewDidLoad];
self.videoPlayerView = [[VIMVideoPlayerView alloc] init];
self.videoPlayerView.translatesAutoresizingMaskIntoConstraints = NO;
self.videoPlayerView.delegate = self;
[self.videoPlayerView setVideoFillMode:AVLayerVideoGravityResizeAspect];
[self.videoPlayerView.player enableTimeUpdates];
[self.videoPlayerView.player enableAirplay];
[self.view addSubview:self.videoPlayerView];
NSDictionary *views = NSDictionaryOfVariableBindings(_videoPlayerView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_videoPlayerView]-0-|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_videoPlayerView]-0-|" options:0 metrics:nil views:views]];
//this is the kind of url I want to load
NSURL *URL = [NSURL URLWithString:@"https://player.vimeo.com/video/51806929"];
[self.videoPlayerView.player setURL:URL];
[self.videoPlayerView.player play];
}
感谢您的帮助。
这不是 URL 视频文件 (https://player.vimeo.com/video/51806929
),它是 URL 网页。
URLs 传递给视频播放器应该是 URLs 到实际的视频文件资源。
您可以通过将 mp4 文件放到服务器上并将该 URL 传递给播放器来测试 VIMVideoPlayer。
如果您是 Vimeo PRO 帐户用户,当您从 Vimeo API 请求 JSON 特定视频或视频列表时,您会看到 VideoFile
个对象与每个 video
个对象关联。这些代表该特定视频的各种分辨率视频文件。每个都有一个URL。您可以将此 URL 传递给播放器。
如果您有任何问题,请告诉我们!
我正在 Objective C 中制作一个 iOS 应用程序,它必须使用 vimeo 网址加载视频。我想使用视频播放器,我用了这个:https://github.com/vimeo/VIMVideoPlayer。 我按照自述说明进行操作,但是我无法阅读 vimeo 视频,出现错误:
Video player Status Failed: error = Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo=0x7f9c5d17b8c0 {NSUnderlyingError=0x7f9c5d176910 "The operation couldn’t be completed. (OSStatus error -12847.)", NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open}
这是我的代码:
-(void)viewDidLoad
{
[super viewDidLoad];
self.videoPlayerView = [[VIMVideoPlayerView alloc] init];
self.videoPlayerView.translatesAutoresizingMaskIntoConstraints = NO;
self.videoPlayerView.delegate = self;
[self.videoPlayerView setVideoFillMode:AVLayerVideoGravityResizeAspect];
[self.videoPlayerView.player enableTimeUpdates];
[self.videoPlayerView.player enableAirplay];
[self.view addSubview:self.videoPlayerView];
NSDictionary *views = NSDictionaryOfVariableBindings(_videoPlayerView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_videoPlayerView]-0-|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_videoPlayerView]-0-|" options:0 metrics:nil views:views]];
//this is the kind of url I want to load
NSURL *URL = [NSURL URLWithString:@"https://player.vimeo.com/video/51806929"];
[self.videoPlayerView.player setURL:URL];
[self.videoPlayerView.player play];
}
感谢您的帮助。
这不是 URL 视频文件 (https://player.vimeo.com/video/51806929
),它是 URL 网页。
URLs 传递给视频播放器应该是 URLs 到实际的视频文件资源。
您可以通过将 mp4 文件放到服务器上并将该 URL 传递给播放器来测试 VIMVideoPlayer。
如果您是 Vimeo PRO 帐户用户,当您从 Vimeo API 请求 JSON 特定视频或视频列表时,您会看到 VideoFile
个对象与每个 video
个对象关联。这些代表该特定视频的各种分辨率视频文件。每个都有一个URL。您可以将此 URL 传递给播放器。
如果您有任何问题,请告诉我们!