Skip to content

Commit

Permalink
Demo video querying in macOS demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
SoneeJohn committed Feb 19, 2020
1 parent a1410e8 commit 1fd56b8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions XCDYouTubeKit Demo/OS X Demo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,30 @@ - (IBAction) playVideo:(id)sender
[self.progressIndicator startAnimation:sender];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:[sender stringValue] completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
[self.progressIndicator stopAnimation:sender];

if (video)
{
NSDictionary *streamURLs = video.streamURLs;
NSURL *url = streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming] ?: streamURLs[@(XCDYouTubeVideoQualityHD720)] ?: streamURLs[@(XCDYouTubeVideoQualityMedium360)] ?: streamURLs[@(XCDYouTubeVideoQualitySmall240)];
AVPlayer *player = [AVPlayer playerWithURL:url];
self.playerView.player = player;
[player play];

[[XCDYouTubeClient defaultClient] queryVideo:video cookies:nil completionHandler:^(NSDictionary * _Nonnull streamURLs, NSError * _Nullable streamError, NSDictionary<id,NSError *> * _Nonnull streamErrors)
{
[self.progressIndicator stopAnimation:sender];

if (streamURLs)
{
NSURL *url = streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming] ?: streamURLs[@(XCDYouTubeVideoQualityHD720)] ?: streamURLs[@(XCDYouTubeVideoQualityMedium360)] ?: streamURLs[@(XCDYouTubeVideoQualitySmall240)];
AVPlayer *player = [AVPlayer playerWithURL:url];
self.playerView.player = player;
[player play];
}
else
{
[[NSAlert alertWithError:streamError] runModal];
}
}];
}
else
{
[self.progressIndicator stopAnimation:sender];
[[NSAlert alertWithError:error] runModal];
}
}];
Expand Down

0 comments on commit 1fd56b8

Please sign in to comment.