I want to play my video just like youtube in iOS using objective C and video file come from a URL. Can anyone guide me how to do this or there is any way to do video buffering in an efficient way.
Buffering like you tube can be accomplished with native Objective C "MPMovieController". You can check out this 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 handle notifications by defining its selector 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];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With