如何阻止 MPMoviePlayerController 显示“无法播放此电影。”?

发布于 2024-09-12 18:45:29 字数 157 浏览 4 评论 0原文

我使用 MPMoviePlayerController 在 iPhone 上播放一些视频和音频流。

有时某些 Steam 不可用,因此在 iPhone OS 3.1 上,即使我收到了所有通知,我也会收到 4 条“此电影无法播放”警报。

谁能告诉我如何防止这种情况发生?

I use MPMoviePlayerController to play some Video and Audio streams on iPhone.

Sometimes some steams aren't available, so on iPhone OS 3.1 I get 4 "This movie could not be played" alerts, even if I catch all the notifications.

Can anyone tell me how to prevent this from happening?

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

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

发布评论

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

评论(2

忘东忘西忘不掉你 2024-09-19 18:45:29

为了防止 MPMoviePlayerController 显示 UIAlertView 警报,您可以使用以下方法:

将以下方法添加到您的应用程序委托中,并确保调用 patchMPVVC 仅在启动时一次

#import "/usr/include/objc/objc-runtime.h"

- (void)_handleError:(NSNotification *)notification {
    // do nothing, or add any custom error handling code here
}

- (void)patchMPVVC {
    // add the _handleError: method to the MPVideoViewController class
    Class class = NSClassFromString(@"MPVideoViewController");
    Method myMethod = class_getInstanceMethod([self class], @selector(_handleError:));
    class_addMethod(class, @selector(_handleError:), method_getImplementation(myMethod), "v@:@");

    // swap method implementations:
    SEL selector = sel_registerName("_videoView_playbackErrorNotification");
    Method originalMethod = class_getInstanceMethod(class, selector);       
    myMethod = class_getInstanceMethod(class, @selector(_handleError:));
    method_exchangeImplementations(originalMethod, myMethod);
}

请记住,此代码可能会被苹果拒绝,因为它引用了私有 MPVideoViewController 类和 _videoView_playbackErrorNotification 方法。

in order to prevent the MPMoviePlayerController from displaying UIAlertView alerts, you can use the following approach:

add the following methods to your application delegate, and make sure to call patchMPVVC only once on startup:

#import "/usr/include/objc/objc-runtime.h"

- (void)_handleError:(NSNotification *)notification {
    // do nothing, or add any custom error handling code here
}

- (void)patchMPVVC {
    // add the _handleError: method to the MPVideoViewController class
    Class class = NSClassFromString(@"MPVideoViewController");
    Method myMethod = class_getInstanceMethod([self class], @selector(_handleError:));
    class_addMethod(class, @selector(_handleError:), method_getImplementation(myMethod), "v@:@");

    // swap method implementations:
    SEL selector = sel_registerName("_videoView_playbackErrorNotification");
    Method originalMethod = class_getInstanceMethod(class, selector);       
    myMethod = class_getInstanceMethod(class, @selector(_handleError:));
    method_exchangeImplementations(originalMethod, myMethod);
}

just keep in mind that this code might be rejected by apple due to the fact that it references the private MPVideoViewController class and _videoView_playbackErrorNotification method.

不爱素颜 2024-09-19 18:45:29

我很遗憾地告诉您,(据我所知)这是不可能做到的。
我也处理过同样的问题,尽管我花了很多时间调查这个问题,但我找不到解决方案。

I'm sorry to tell you that this is (to the best of my knowledge) not possible to do.
I've dealt with the same issue too and even though I spent quite a lot of time investigating the issue, I couldn't find a solution.

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