我使用MPMoviePlayerController
在iPhone上播放一些视频和音频流。如何阻止MPMoviePlayerController显示“这部电影无法播放。”?
有时某些蒸汽不可用,所以在iPhone OS 3.1上,即使我收到所有通知,我也会得到4个“这部电影无法播放”警报。
谁能告诉我如何防止这种情况发生?
我使用MPMoviePlayerController
在iPhone上播放一些视频和音频流。如何阻止MPMoviePlayerController显示“这部电影无法播放。”?
有时某些蒸汽不可用,所以在iPhone OS 3.1上,即使我收到所有通知,我也会得到4个“这部电影无法播放”警报。
谁能告诉我如何防止这种情况发生?
我很遗憾地告诉你,这是(据我所知)不可能做到。 我也处理过同样的问题,即使我花了很多时间调查问题,但找不到解决方案。
为了防止MPMoviePlayerController
从显示0警报,您可以用下面的办法:
以下方法添加到您的应用程序委托,并确保调用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), "[email protected]:@");
// 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
方法,因此该代码可能会被苹果拒绝。
+1用于使用私有API进行尝试 – vodkhang 2010-09-07 10:20:05
我也是。我放弃了:(在我的应用程序中,我有更好的方法来通知警报/错误,但现在我必须接受这个不一致 – vodkhang 2010-08-12 17:23:49
是的,试着在苹果开发者网站上提交一个“bug”或功能请求。未来版本 – samsam 2010-08-13 07:16:36