最近在用 ios VLC 2.2.2 播放h264視頻流時,如果視頻流服務端出了故障,VLC播放器就會出現(xiàn)“Your input can't be opened, VLC is unable to open the MRL” 的英文提示框,由于VLC這段提示語是英文的,沒有多國語言翻譯。對于不認識英文的用戶,簡直就是一段亂碼,影響用戶體驗,故思考如何解決這個問題。
Your input can't be opened
VLC is unable to open the MRL 'file:///var/mobile/Media/DCIM/102APPLE/IMG2728.MOV'.
Check the log for details.
截圖-1
第一種做法: 在VLC源碼中找到這段代碼,注釋掉就可以了! 搜索過程中發(fā)現(xiàn)這段代碼只存在于2.2.2的一個input.c文件中。
注釋掉這段代碼,需要重新編譯和打包VLC,生成framework,如果你不嫌麻煩,可以試試!
第二種做法:通過 [截圖-1] 可以看出這個彈框是ios系統(tǒng)自帶的UIAlertView,那么它要顯示出來肯定要調(diào)用-(void)show;方法,我們利用runtime的方法交換可以對這種情況進行攔截。
具體做法是創(chuàng)建一個UIAlertView的分類,直接拖入項目當中就ok:
// UIAlertView+VLCLog.h
#import <UIKit/UIKit.h>
@interface UIAlertView (VLCLog)
@end
// UIAlertView+VLCLog.m
#import "UIAlertView+VLCLog.h"
#import <objc/runtime.h>
@implementation UIAlertView (VLCLog)
//此分類為了攔截VLC無法打開實時流時出現(xiàn)的英文UIAlert彈框
+ (void)load {
Method sysMethod = class_getInstanceMethod([self class], @selector(show));
Method myMethod = class_getInstanceMethod([self class], @selector(myShow));
method_exchangeImplementations(sysMethod, myMethod);
}
- (void)myShow {
if ([self.message containsString:@"VLC is unable to open the MRL"]) {
[self dismissWithClickedButtonIndex:0 animated:NO];
} else {
[self myShow];
}
}
@end
也可以攔截該方法,修改Vlc原來那段英文提示語,改為展示給用戶看的已翻譯的文字。
#import "UIAlertView+VLCLog.h"
#import <objc/runtime.h>
@implementation UIAlertView (VLCLog)
//此分類為了攔截VLC無法打開實時流時出現(xiàn)的英文UIAlert彈框
+ (void)load {
Method sysMethod = class_getInstanceMethod([self class], @selector(show));
Method myMethod = class_getInstanceMethod([self class], @selector(myShow));
method_exchangeImplementations(sysMethod, myMethod);
}
- (void)myShow {
if ([self.message containsString:@"VLC is unable to open the MRL"]) {
self.title = GETLANGUAGES(@"輸入的地址無法打開", nil);
self.message = GETLANGUAGES(@"重啟視頻流服務器試試吧!", nil);
[self myShow];
} else {
[self myShow];
}
}
@end