【问题标题】:How to stop MPMoviePlayerController from showing "This movie could not be played."?如何阻止 MPMoviePlayerController 显示“无法播放此电影。”?
【发布时间】:2010-08-06 08:20:06
【问题描述】:

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

有时某些 Steam 不可用,因此在 iPhone OS 3.1 上,即使我收到所有通知,我也会收到 4 个“无法播放这部电影”警报。

谁能告诉我如何防止这种情况发生?

【问题讨论】:

    标签: iphone objective-c mpmovieplayercontroller ios-3.x


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      很遗憾地告诉您,(据我所知)这是不可能的。 我也处理过同样的问题,尽管我花了很多时间调查这个问题,但我找不到解决方案。

      【讨论】:

      • 我也是。我放弃了:(。在我的应用程序中,我有更好的方法来通知警报/错误,但现在我必须接受这种不一致
      • 是的,尝试在苹果开发者网站提交“错误”或功能请求。也许这会保留在未来的版本中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多