Reputation: 2455
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.
Upvotes: 3
Views: 727
Reputation: 321
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];
}
}
Upvotes: 1