在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:0xced/XCDYouTubeKit开源软件地址:https://github.com/0xced/XCDYouTubeKit开源编程语言:Objective-C 94.4%开源软件介绍:AboutXCDYouTubeKit is a YouTube video player for iOS, tvOS and macOS. Are you enjoying XCDYouTubeKit? You can say thank you with a tweet. I am also accepting donations. ;-) Requirements
WarningXCDYouTubeKit is against the YouTube Terms of Service. The only official way of playing a YouTube video inside an app is with a web view and the iframe player API. Unfortunately, this is very slow and quite ugly, so I wrote this player to give users a better viewing experience. InstallationXCDYouTubeKit is available through CocoaPods, Carthage and Swift Package Manager. CocoaPods: pod "XCDYouTubeKit", "~> 2.15" Carthage: github "0xced/XCDYouTubeKit" ~> 2.15 Swift Package Manager: Add dependencies: [
.package(url: "https://github.com/0xced/XCDYouTubeKit.git", from: "2.15.0")
] Alternatively, you can manually use the provided static library or dynamic framework. In order to use the static library, you must:
These steps will ensure that UsageXCDYouTubeKit is fully documented. iOS 8.0+ & tvOS (AVPlayerViewController)AVPlayerViewController *playerViewController = [AVPlayerViewController new];
[self presentViewController:playerViewController animated:YES completion:nil];
__weak AVPlayerViewController *weakPlayerViewController = playerViewController;
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoIdentifier completionHandler:^(XCDYouTubeVideo * _Nullable video, NSError * _Nullable error) {
if (video)
{
NSDictionary *streamURLs = video.streamURLs;
NSURL *streamURL = streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming] ?: streamURLs[@(XCDYouTubeVideoQualityHD720)] ?: streamURLs[@(XCDYouTubeVideoQualityMedium360)] ?: streamURLs[@(XCDYouTubeVideoQualitySmall240)];
weakPlayerViewController.player = [AVPlayer playerWithURL:streamURL];
[weakPlayerViewController.player play];
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}]; iOS, tvOS and macOSNSString *videoIdentifier = @"9bZkp7q19f0"; // A 11 characters YouTube video identifier
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoIdentifier completionHandler:^(XCDYouTubeVideo *video, NSError *error) {
if (video)
{
// Do something with the `video` object
}
else
{
// Handle error
}
}]; iOS 8.0On iOS, you can use the class Present the video in full-screen- (void) playVideo
{
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"9bZkp7q19f0"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer];
[self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];
}
- (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:notification.object];
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (finishReason == MPMovieFinishReasonPlaybackError)
{
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
// Handle error
}
}
Present the video in a non full-screen viewXCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"9bZkp7q19f0"];
[videoPlayerViewController presentInView:self.videoContainerView];
[videoPlayerViewController.moviePlayer play]; See the demo project for more sample code. LoggingSince version 2.2.0, XCDYouTubeKit produces logs. XCDYouTubeKit supports CocoaLumberjack but does not require it. See the CreditsThe URL extraction algorithms in XCDYouTubeKit are inspired by the YouTube extractor module of the youtube-dl project. ContactCédric Luthi LicenseXCDYouTubeKit is available under the MIT license. See the LICENSE file for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论