【发布时间】:2010-08-06 08:20:06
【问题描述】:
我使用MPMoviePlayerController 在 iPhone 上播放一些视频和音频流。
有时某些 Steam 不可用,因此在 iPhone OS 3.1 上,即使我收到所有通知,我也会收到 4 个“无法播放这部电影”警报。
谁能告诉我如何防止这种情况发生?
【问题讨论】:
标签: iphone objective-c mpmovieplayercontroller ios-3.x
我使用MPMoviePlayerController 在 iPhone 上播放一些视频和音频流。
有时某些 Steam 不可用,因此在 iPhone OS 3.1 上,即使我收到所有通知,我也会收到 4 个“无法播放这部电影”警报。
谁能告诉我如何防止这种情况发生?
【问题讨论】:
标签: iphone objective-c mpmovieplayercontroller ios-3.x
为了防止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 方法。
【讨论】:
很遗憾地告诉您,(据我所知)这是不可能的。 我也处理过同样的问题,尽管我花了很多时间调查这个问题,但我找不到解决方案。
【讨论】: