ios VLC 2.2.2 出现Your input can't be opened, VLC is unable to open the MRL问题

最近在用 ios VLC 2.2.2 播放h264视频流时,如果视频流服务端出了故障,VLC播放器就会出现“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.
ios VLC 2.2.2 出现Your input can't be opened, VLC is unable to open the MRL问题_第1张图片
截图-1

第一种做法: 在VLC源码中找到这段代码,注释掉就可以了! 搜索过程中发现这段代码只存在于2.2.2的一个input.c文件中。

ios VLC 2.2.2 出现Your input can't be opened, VLC is unable to open the MRL问题_第2张图片

注释掉这段代码,需要重新编译和打包VLC,生成framework,如果你不嫌麻烦,可以试试!

第二种做法:通过 [截图-1] 可以看出这个弹框是ios系统自带的UIAlertView,那么它要显示出来肯定要调用-(void)show;方法,我们利用runtime的方法交换可以对这种情况进行拦截。

具体做法是创建一个UIAlertView的分类,直接拖入项目当中就ok:


ios VLC 2.2.2 出现Your input can't be opened, VLC is unable to open the MRL问题_第3张图片
//  UIAlertView+VLCLog.h
#import 
@interface UIAlertView (VLCLog)
@end

//  UIAlertView+VLCLog.m
#import "UIAlertView+VLCLog.h"
#import 

@implementation UIAlertView (VLCLog)

//此分类为了拦截VLC无法打开实时流时出现的英文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 

@implementation UIAlertView (VLCLog)

//此分类为了拦截VLC无法打开实时流时出现的英文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

你可能感兴趣的:(ios VLC 2.2.2 出现Your input can't be opened, VLC is unable to open the MRL问题)