代码之家  ›  专栏  ›  技术社区  ›  mxg

如何阻止mpmovieplayercontroller显示“无法播放此电影”。?

  •  1
  • mxg  · 技术社区  · 14 年前

    我用 MPMoviePlayerController 在iPhone上播放一些视频和音频流。

    有时有些流媒体不可用,所以在iPhoneOS3.1上,我会收到4条“这部电影无法播放”的警报,即使我捕捉到了所有的通知。

    有人能告诉我如何防止这种情况发生吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Xyz    7 年前

    我很抱歉地告诉你(据我所知)这是不可能做到的。 我也处理过同样的问题,尽管我花了很多时间调查这个问题,但我还是找不到解决办法。

        2
  •  2
  •   dormin    14 年前

    为了防止 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 方法。