ytvimeoextractorは、VimeoビデオのMP4ストリームを抽出し、 MPMoviePlayerViewController
またはAVPlayerView
を介して再生できるようにします。
クラス | 目的 |
---|---|
YTVimeoExtractor | YTVimeoExtractor はメインクラスであり、その唯一の目的はVimeoビデオに関する情報を取得することです。 2つの主要なメソッドfetchVideoWithIdentifier:withReferer:completionHandler: またはfetchVideoWithVimeoURL:withReferer:completionHandler: ビデオ情報を取得するには。 |
YTVimeoExtractorOperation | YTVimeoExtractorOperation 、 NSOperation のサブクラスであり、Vimeoビデオに関する情報を取得して解析するために使用されます。これは低レベルのクラスです。一般的に言えば、より高いレベルのYTVimeoExtractor クラスを使用する必要があります。 |
YTVimeoURLParser | YTVimeoURLParser は、パットVimeo URLを検証および解析するために使用されます。クラスの主な目的は、特定のURLをYTVimeoExtractor クラスで処理できるかどうかを確認することです。 |
YTVimeoVideo | YTVimeoVideo Vimeoビデオを表しています。このクラスを使用して、特定のビデオに関する情報にアクセスします。 YTVimeoVideo オブジェクトを手動で初期化しないでください。 -init メソッドを使用すると、例外がスローされ、代わりにYTVimeoExtractor クラスの2つの主要なメソッドを使用して、 YTVimeoVideo オブジェクトを取得します。 |
設置の好ましい方法は、ココアポッドを介して行われます。 Podfileに追加してください
pod 'YTVimeoExtractor'
pod install
実行します。
または、YTVimeOextractorフォルダーをプロジェクトにコピーするだけです。
# import " YTVimeoExtractor.h "
Carthageは、依存関係を構築し、バイナリフレームワークを提供する分散型依存関係マネージャーです。
次のコマンドを使用して、HomeBrewでCarthageをインストールできます。
$ brew update
$ brew install carthage
ytvimeoextractorをCarthageを使用してXcodeプロジェクトに統合するには、 Cartfile
で指定します。
github "lilfaf/YTVimeoExtractor"
carthage
を実行してフレームワークを構築し、構築されたYTVimeoExtractor.framework
Xcodeプロジェクトにドラッグします。
YTVimeoExtractor
クラスで2つのブロックメソッドを使用します。どちらの方法でも、メインスレッドで実行される完了ハンドラーを呼び出します。完了ハンドラーがゼロの場合、例外がスローされます。 completehandlerには、操作が正常に完了した場合、2つのパラメーターが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ライセンスに基づいてライセンスされています。詳細については、ライセンスファイルを参照してください。