I have complete my whole video player in working condition but still can't do buffering. Was trying this method: How to show buffered data on UISlider using MpMoviePlayerController in iOS? but it doesn't work. i failed even in first step due to errors in code. Here is my code for slider.
-(void) playMethod {
NSURL *url = [[NSURL alloc] initWithString:urlStr.text];
movie = [[MPMoviePlayerController alloc]initWithContentURL:url];
[movie setMovieSourceType:MPMovieSourceTypeFile];
[movie.view setFrame:self.view.frame];
[movie prepareToPlay];
movie.controlStyle = MPMovieControlStyleNone;
movie.fullscreen = YES;
movie.shouldAutoplay = YES;
[movie setScalingMode:MPMovieScalingModeAspectFill];
//[movie setCurrentPlaybackRate:2.f];
[self.movie setFullscreen:YES animated:NO];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerLoadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[self.view addSubview:movie.view];
progressbar=[[UISlider alloc]init];
[progressbar setFrame:CGRectMake(75,self.view.frame.size.height - 35 + 2, self.view.frame.size.width - 75 - 105 - 10, 20)];
[progressbar setMinimumTrackImage:[UIImage imageNamed:@"RedLine1.png"] forState:UIControlStateNormal];
[progressbar setMaximumTrackImage:[UIImage imageNamed:@"GrayLine1.png"] forState:UIControlStateNormal];
[progressbar setThumbImage:[UIImage imageNamed:@"Thumb.png"] forState:UIControlStateNormal];
[progressbar addTarget:self action:@selector(sliderforprogressbar:) forControlEvents:UIControlEventTouchUpInside];
[playerView addSubview:progressbar];
}
- (IBAction)sliderforprogressbar:(id)sender
{
movie.currentPlaybackTime = progressbar.value * movie.duration;
}
- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification
{
if ((movie.loadState & MPMovieLoadStatePlaythroughOK) == MPMovieLoadStatePlaythroughOK)
{
int seconds = (int)movie.duration;
int remainder = seconds % 3600;
int hours = seconds / 3600;
int minutes = remainder / 60;
int forSeconds = remainder % 60;
timeDisplay.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours,minutes,forSeconds];
}
}
I can show you more code if any one interested, but just focus on progressbar for my issue. Any idea how can i do buffering here?