ytvimeoextractor는 Vimeo 비디오의 MP4 스트림을 추출한 다음 MPMoviePlayerViewController
또는 AVPlayerView
통해 재생하는 데 사용할 수 있습니다.
수업 | 목적 |
---|---|
YTVimeoExtractor | YTVimeoExtractor 는 주요 클래스이며 그 유일한 목적은 Vimeo 비디오에 대한 정보를 가져 오는 것입니다. 두 가지 주요 방법을 사용하여 fetchVideoWithIdentifier:withReferer:completionHandler: 또는 fetchVideoWithVimeoURL:withReferer:completionHandler: 비디오 정보를 얻으려면 두 가지 주요 방법을 사용하십시오. |
YTVimeoExtractorOperation | YTVimeoExtractorOperation NSOperation 의 서브 클래스이며 Vimeo 비디오에 대한 정보를 가져오고 구문 분석하는 데 사용됩니다. 이것은 낮은 레벨 클래스입니다. 일반적으로 더 높은 수준의 YTVimeoExtractor 클래스를 사용해야합니다. |
YTVimeoURLParser | YTVimeoURLParser 는 vimeo urls를 유효성을 검사하고 구문 분석하는 데 사용됩니다. 클래스의 주요 목적은 YTVimeoExtractor 클래스에서 주어진 URL을 처리 할 수 있는지 확인하는 것입니다. |
YTVimeoVideo | YTVimeoVideo vimeo 비디오를 나타냅니다. 이 클래스를 사용하여 특정 비디오에 대한 정보에 액세스하십시오. YTVimeoVideo 객체를 수동으로 초기화하지 마십시오. -init 메소드를 사용하면 예외가 발생하여 YTVimeoExtractor 클래스의 두 가지 주요 방법을 사용하여 YTVimeoVideo 객체를 얻으십시오. |
선호하는 설치 방법은 코코아포드를 통한 것입니다. Podfile에 추가하십시오
pod 'YTVimeoExtractor'
pod install
실행하십시오.
또는 ytvimeoextractor 폴더를 프로젝트에 복사 할 수 있습니다.
# import " YTVimeoExtractor.h "
Carthage는 종속성을 구축하고 이진 프레임 워크를 제공하는 분산 형 종속 관리자입니다.
다음 명령을 사용하여 Homebrew로 Carthage를 설치할 수 있습니다.
$ brew update
$ brew install carthage
Carthage를 사용하여 ytvimeoextractor를 Xcode 프로젝트에 통합하려면 Cartfile
에 지정하십시오.
github "lilfaf/YTVimeoExtractor"
carthage
실행하여 프레임 워크를 구축하고 빌드 된 YTVimeoExtractor.framework
를 Xcode 프로젝트로 드래그하십시오.
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 라이센스에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.