1

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?

Community
  • 1
  • 1
Nasir Khan
  • 723
  • 4
  • 12
  • 24
  • Means u can't see buffered (While video is buffering)...state ? Can you explain first two lines of your question more specifically. – Arpit B Parekh Aug 18 '15 at 06:09
  • @ArpitParekh i am actually creating custom player... jus want to add buffering. I have tried different methods like mentioned above but couldn't do it... as i can't show another bar in UISlider ... one bar is displaying max image and one is for currentPlaybacktime... now how can i add another bar for PlayableDuration (Buffering) – Nasir Khan Aug 18 '15 at 06:15
  • So, you can manage two bars. Or you have a problem in coding of Buffering ? – Arpit B Parekh Aug 18 '15 at 06:20
  • @ArpitParekh Can i add 2 bars? in UISlider... i can do buffering i just dont know how to show that in slider.... like if i give slider value: playableduration/duration ... it will give me buffering time... but if i show the buffering how would i show the current time – Nasir Khan Aug 18 '15 at 06:22
  • Is there any facility of MPMoviePlayer to show default bar, which it self showing buffered bar when required ? – Arpit B Parekh Aug 18 '15 at 06:23
  • yes but i am not using default controls. – Nasir Khan Aug 18 '15 at 06:27

1 Answers1

0

Okay I have done this with totally new way, IDK if anyone has a better idea then please share it.

UIImageView *progressbarBG = [[UIImageView alloc]initWithFrame:CGRectMake(75+5,self.view.frame.size.height - 35 + 5, self.view.frame.size.width - 75 - 105 - 10  - 10, 20 - 5)];
progressbarBG.image = [UIImage imageNamed:@"GrayLine1.png"];
[playerView addSubview:progressbarBG];

//progressbarBuffering = [[UIImageView alloc]initWithFrame:CGRectMake(80,self.view.frame.size.height - 30, self.view.frame.size.width - 200, 15)];
progressbarBuffering = [[UIImageView alloc]init];
progressbarBuffering.image = [UIImage imageNamed:@"LightRedLine.png"];
[playerView addSubview:progressbarBuffering];


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 setMaximumTrackImage:[UIImage imageNamed:@"BlankBar.png"] forState:UIControlStateNormal];
[progressbar setThumbImage:[UIImage imageNamed:@"Thumb.png"] forState:UIControlStateNormal];
[progressbar addTarget:self action:@selector(sliderforprogressbar:) forControlEvents:UIControlEventTouchUpInside];
[playerView addSubview:progressbar];

[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updatePlaybackTime:) userInfo:nil repeats:YES];



- (void)updatePlaybackTime:(NSTimer*)theTimer {
progressbarBuffering.frame = CGRectMake(80,self.view.frame.size.height - 30, (self.view.frame.size.width - 200)*(movie.playableDuration/movie.duration), 15); 
}

I created two background Imageviews one for gray background image, and one with light red image, and added blank png image atMaximumTrackImage of Progressbar. and then i am just resizing the light red image as per playableduration as mentioned in code.

Nasir Khan
  • 723
  • 4
  • 12
  • 24