3

Is there a way to determine the bit-rate of the stream an MPMovieController is playing? I am programming in objective-c on iOS

eshalev
  • 3,033
  • 4
  • 34
  • 48

2 Answers2

4

You can get the indicated bit rate from event, which is the bit rate of the stream according to the m3u8. To calculate the actual bit rate I divide event.numberOfBytesTransferred / event.durationWatched and multiply by 8.

NSArray *events = self.player.accessLog.events;
    MPMovieAccessLogEvent *event = (MPMovieAccessLogEvent *)[events lastObject];
double calculatedBitRate = 8 * event.numberOfBytesTransferred / event.durationWatched;
    value = [nf stringFromNumber:[NSNumber numberWithDouble:calculatedBitRate]];
    self.calculatedBitRateLabel.text = [NSString stringWithFormat:@"My calculated bit rate = %@", value];
marxy
  • 416
  • 2
  • 10
  • I find the above bit rate calculation given by you shows me a very high bit rate value , can you please explain me more on this please . – karthik Sep 04 '15 at 21:19
2

Found it, the "accessLog" gives you periodic stats which include the observed bitrate:

MPMovieAccessLogEvent *evt=nil;
MPMovieAccessLog *accessL=[moviePlayer accessLog];
NSArray *events = accessL.events;
for (int i=0; i<[events count]; i++) {
    evt=[events objectAtIndex:i];
}
return evt.observedBitrate
eshalev
  • 3,033
  • 4
  • 34
  • 48
  • Can u please explain in detail about how we can find the progress timings of a video using the above code? Where do we need to use the above logic? Should this be used when we define the MPMoviePlayerController? – Pradeep Reddy Kypa Apr 06 '12 at 09:37
  • I tried to implement this on a button click but i am getting this in the below format. The access log is 10097249, The access log is 10035010. But i want to get the actual timing of the video is played. I have a button down the video.I want to capture that particular timing of a video when the button is cliked. Can you please help me on this? – Pradeep Reddy Kypa Apr 06 '12 at 09:47
  • 1
    Above code is to get the current bit-rate of the Stream, not the position. There are other stats in the evt (one of them might give you the info you need) – eshalev Apr 15 '12 at 07:32
  • You need to wrap this code in a method that gets messaged by an NSTimer. – Nate Potter Aug 13 '14 at 20:48
  • @eshalev : Can you please guide me how to utitlize this to switch the URL stream? – Pooja M. Bohora Jul 03 '15 at 10:26