playableDuration 在 iOS5 中返回 0

发布于 2024-12-09 22:23:16 字数 773 浏览 3 评论 0原文

有没有其他人注意到 MPMoviePlayerController 类的 playableDuration 属性在 iOS 5 中总是返回 0。这在以前的 iOS 版本中工作得很好。我用它来设置进度条的值。

下面是一段代码,过去在 4.x SDK 下工作得很好(即,playableDuration 属性在缓冲流时返回正确的非零值),但在 SDK 5.x 下它总是返回零。

- (void) updateMeter {
NSLog(@"playableDuration = %f", streamPlayer.playableDuration);
}

- (void)viewDidLoad
{

[super viewDidLoad];
streamPlayer = [[MPMoviePlayerController alloc] 
initWithContentURL:[NSURL    URLWithString:@"http://99.198.118.250:8158/"]];    

NSTimer *updateBarTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 
                          target:self selector:@selector(updateMeter)    
                          userInfo:nil repeats:YES];

streamPlayer.controlStyle = MPMovieControlStyleEmbedded;
[streamPlayer play];

 }

Has anyone else noticed that playableDuration property of MPMoviePlayerController class always returns 0 in iOS 5. This used to work fine in previous versions of iOS. I use it to set the value of a progress bar.

Here is piece of code that used to work under 4.x SDK just fine (i.e., the playableDuration attribute returned the correct non-zero value while buffering the stream), but under SDK 5.x it always returns zero.

- (void) updateMeter {
NSLog(@"playableDuration = %f", streamPlayer.playableDuration);
}

- (void)viewDidLoad
{

[super viewDidLoad];
streamPlayer = [[MPMoviePlayerController alloc] 
initWithContentURL:[NSURL    URLWithString:@"http://99.198.118.250:8158/"]];    

NSTimer *updateBarTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 
                          target:self selector:@selector(updateMeter)    
                          userInfo:nil repeats:YES];

streamPlayer.controlStyle = MPMovieControlStyleEmbedded;
[streamPlayer play];

 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-12-16 22:23:16

使用您的确切代码,但将网址替换为: http://devimages.apple .com/iphone/samples/bibpbop/gear1/prog_index.m3u8

对我来说,除非我将播放器指向分段的 .m3u8 文件,否则您的代码会失败。

我在计算机本地对 .mp4 电影和 .mp3 音频文件进行了一些测试,两者都运行良好。

我在这里推测,但我相信在流媒体时,MPMoviePlayerController 可能正在使用 .m3u8 文件动态推断播放器项目数据?无论如何,这就是我的猜测。奇怪的是,如果是这种情况,为什么它对您的网址有效?这引出了我的下一条评论...

使用 AVFoundation 而不是 MediaPlayer 框架可能会得到更好的结果。我在自己的工作中也转向了它。它的“预先包装”较少,但提供了更多的控制。

Use your exact code but replace the url with: http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8

For me your code failed unless I pointed the player to a segmented .m3u8 file.

I did some tests with a .mp4 movie and an .mp3 audio file locally on my computer and both worked fine as well.

I'm speculating here but I believe it's probable that while streaming media, the MPMoviePlayerController is using the .m3u8 file to deduce player item data on the fly? That's my guess anyway. What's curious is that if this is the case, why does it work at all for your url? Which leads me to my next comment...

You would probably have better results using AVFoundation rather than the MediaPlayer framework. I switched to it in my own work as well. It's less "prepackaged" but simply provides much more control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文