我使用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