Comments (4)
Here is how to you can achieve a playlist.
First, you need to unregister for the MPMoviePlayerPlaybackDidFinishNotification
in order for the player not to dismiss automatically at the end of the video.
static void *MoviePlayerContentURLContext = &MoviePlayerContentURLContext;
- (IBAction) play:(id)sender
{
self.videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:firstVideoIdentifier];
[[NSNotificationCenter defaultCenter] removeObserver:self.videoPlayerViewController name:MPMoviePlayerPlaybackDidFinishNotification object:self.videoPlayerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.videoPlayerViewController.moviePlayer];
[self.videoPlayerViewController addObserver:self forKeyPath:@"moviePlayer.contentURL" options:(NSKeyValueObservingOptions)0 context:MoviePlayerContentURLContext];
[self presentMoviePlayerViewControllerAnimated:self.videoPlayerViewController];
}
Then you need to handle the notification yourself. Manage hasNextVideo and nextVideoIdentifier how it makes sense for you.
- (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (finishReason == MPMovieFinishReasonPlaybackEnded && [self hasNextVideo])
self.videoPlayerViewController.videoIdentifier = [self nextVideoIdentifier];
else
[self dismissMoviePlayerViewControllerAnimated];
}
You also need to register yourself as an observer of the movie player contentURL
to automatically start playing the next video.
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == MoviePlayerContentURLContext)
[self.videoPlayerViewController.moviePlayer play];
else
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
from xcdyoutubekit.
Is it possible to get different notifications on single tap on the fast forward and rewind button? at the moment it will only go forward to the next video even when you click rewind. Is this possible?
from xcdyoutubekit.
I really appreciate your work on this framework but I'm trying to simulate a playlist and play various videos. The problem is that when i click on the rewind button it do the same as the forward button. Is there an notification for the rewind button? How can i do the rewind button act like a previous button when clicked?
from xcdyoutubekit.
@0xced perfect example for playlist
from xcdyoutubekit.
Related Issues (20)
- Error Domain=XCDYouTubeVideoErrorDomain Code=-3 "(null)" HOT 4
- Can't get the streamUrl of Live Stream HOT 11
- CP=βThis is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info.β
- No longer works: XCDYouTubeVideoErrorDomain error -3 HOT 22
- Unable to play youtube video in iOS app HOT 10
- getVideoWithIdentifier return XCDYouTubeVideoErrorDomain error HOT 25
- streamURL = nil for "LIVE NOW" videos(youtube). HOT 16
- (iOS) XCDYouTubeVideoErrorDomain: -2 with empty User Info for upcoming live stream HOT 2
- XCDYouTubeRequestTypeGetVideoInfo is resulting in a 404 response
- Error XCDYouTubeVideoErrorDomain -2 when i try open video HOT 23
- Error playing video HOT 11
- VIDEO NOT PLAYING (CHECK THIS BEFORE CREATING NEW) HOT 23
- Video Takes a Long Time to Load - Same video performs differently daily HOT 11
- Get StreamUrls from Id is nil HOT 1
- [XCDYouTubeKit] Failed to decode response Code: -3 HOT 7
- Live video plays for last 2:00:00 hours only.
- Cannot play video with XCDYouTubeVideoErrorDomain Code: -2
- live video
- The following content is not available on this app. HOT 1
- Emergency fix HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xcdyoutubekit.