YTVimeoExtractor
Version 1.2.0
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 对象。 |
首选的安装方式是通过Cocoapods。只需添加到您的Podfile
pod 'YTVimeoExtractor'
并运行pod install
。
另外,您只需将ytvimeoextractor文件夹复制到项目即可。
# import " YTVimeoExtractor.h "
迦太基是一个分散的依赖管理器,可建立您的依赖关系并为您提供二进制框架。
您可以使用以下命令使用Homebrew安装迦太基:
$ brew update
$ brew install carthage
要使用迦太基将Ytvimeoextractor集成到您的Xcode项目中,请在您的Cartfile
中指定:
github "lilfaf/YTVimeoExtractor"
运行carthage
以构建框架并将构建的YTVimeoExtractor.framework
拖到Xcode项目中。
在YTVimeoExtractor
类中使用两个块方法。这两种方法都将调用在主线程上执行的完整汉格勒。如果完成处理程序为零,则将抛出一个例外。如果操作成功完成,则完整的Handhandler具有两个参数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许可证的许可。有关更多信息,请参见许可证文件。