YTVimeoExtractor提取Vimeo视频的MP4流,之后可以通过MPMoviePlayerViewController
或AVPlayerView
来播放。
类 | 用途 |
---|---|
YTVimeoExtractor |
YTVimeoExtractor 是主类,其唯一目的是获取Vimeo视频的信息。使用两个主要方法fetchVideoWithIdentifier:withReferer:completionHandler: 或fetchVideoWithVimeoURL:withReferer:completionHandler: 来获取视频信息。 |
YTVimeoExtractorOperation |
YTVimeoExtractorOperation 是NSOperation 的子类,用于获取和解析Vimeo视频的信息。这是一个低级类。一般来说,您应使用高级YTVimeoExtractor 类。 |
YTVimeoURLParser |
YTVimeoURLParser 用于验证和解析Vimeo URL。该类的主要目的是检查给定的URL是否可以由YTVimeoExtractor 类处理。 |
YTVimeoVideo |
YTVimeoVideo 代表一个Vimeo视频。使用此类来访问特定视频的信息。不要手动初始化一个YTVimeoVideo 对象。使用`-init`方法将抛出异常,而是使用`YTVimeoExtractor`类的两个主要方法来获取一个`YTVimeoVideo`对象。 |
使用`YTVimeoExtractor`类中的两个块方法。这两个方法都会调用一个完成处理器,该处理器在主线程上执行。如果完成处理器为nil,则会抛出异常。完成处理器有两个参数:一个`YTVimeoVideo`对象,表示操作成功完成;以及一个`NSError`对象,描述可能发生的网络或解析错误。
[[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:nil completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {
if (video) {
[self.titleTextField setStringValue:video.title];
//Will get the lowest available quality.
//NSURL *lowQualityURL = [video lowestQualityStreamURL];
//Will get the highest available quality.
NSURL *highQualityURL = [video highestQualityStreamURL];
AVPlayer *player = [[AVPlayer alloc]initWithURL:highQualityURL];
self.playerView.player = player;
self.playerView.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.playerView.player play];
[self.playerView becomeFirstResponder];
}else{
[[NSAlert alertWithError:error]runModal];
}
}];
[[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:nil completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {
if (video) {
self.titleLabel.text = [NSString stringWithFormat:@"Video Title: %@",video.title];
//Will get the lowest available quality.
//NSURL *lowQualityURL = [video lowestQualityStreamURL];
//Will get the highest available quality.
NSURL *highQualityURL = [video highestQualityStreamURL];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:highQualityURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
}else{
UIAlertView *alertView = [[UIAlertView alloc]init];
alertView.title = error.localizedDescription;
alertView.message = error.localizedFailureReason;
[alertView addButtonWithTitle:@"OK"];
alertView.delegate = self;
[alertView show];
}
}];
如果Vimeo视频有域名级别限制,并且只能从特定域名播放,添加引用者很简单。
[[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:@"http://www.mywebsite.com" completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {
if (video) {
//Will get the lowest available quality.
//NSURL *lowQualityURL = [video lowestQualityStreamURL];
//Will get the highest available quality.
NSURL *highQualityURL = [video highestQualityStreamURL];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:highQualityURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
}else{
UIAlertView *alertView = [[UIAlertView alloc]init];
alertView.title = error.localizedDescription;
alertView.message = error.localizedFailureReason;
[alertView addButtonWithTitle:@"OK"];
alertView.delegate = self;
[alertView show];
}
}];
YTVimeoExtractor遵循MIT许可证。有关更多信息,请参阅LICENSE文件。