Giter Club home page Giter Club logo

Comments (4)

0xced avatar 0xced commented on July 28, 2024 1

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.

Fredehagelund92 avatar Fredehagelund92 commented on July 28, 2024

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.

devmustache avatar devmustache commented on July 28, 2024

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.

paresh-navadiya avatar paresh-navadiya commented on July 28, 2024

@0xced perfect example for playlist

from xcdyoutubekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.