Play videos like youtube in iOS 8

I want to play my video just like youtube on iOS using C object and video files from url. Can anyone guide me on how to do this, or is there a way to efficiently buffer the video.

+3


source to share


1 answer


Buffering like your pipe can be done with the native Objective C "MPMovieController". You can check this out if it works for you.

    MPMoviePlayerViewController* MPmoviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:nil];
    moviePlayerController.moviePlayer.fullscreen=YES;
    moviePlayerController.moviePlayer.shouldAutoplay=YES;
    [self presentMoviePlayerViewControllerAnimated:moviePlayerController];

      



Declare MPmoviePlayerController a global variable. Then you process the notification by defining its selection methods as per your requirements.

- (void)moviePlaybackComplete:(NSNotification *)notification
{
if([notification.name isEqual:MPMoviePlayerPlaybackDidFinishNotification])
{
    NSError *error = [[notification userInfo] objectForKey:@"error"];
    if (error)
    {
        NSLog(@"Did finish with error: %@", error);
    }
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];
    [moviePlayerController.moviePlayer stop];
    moviePlayerController = nil;
    [self dismissMoviePlayerViewControllerAnimated];
}
else if([notification.name isEqual:MPMoviePlayerWillExitFullscreenNotification])
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerWillExitFullscreenNotification
                                                  object:nil];
    [moviePlayerController.moviePlayer stop];
    moviePlayerController = nil;
    [self dismissMoviePlayerViewControllerAnimated];
}
}

      

+1


source







All Articles