How to stop MPMoviePlayerController from showing "This movie could not be played."?

871 Views Asked by At

I use MPMoviePlayerController to play some Video and Audio streams on iPhone.

Sometimes some steams aren't available, so on iPhone OS 3.1 I get 4 "This movie could not be played" alerts, even if I catch all the notifications.

Can anyone tell me how to prevent this from happening?

2

There are 2 best solutions below

2
On BEST ANSWER

I'm sorry to tell you that this is (to the best of my knowledge) not possible to do. I've dealt with the same issue too and even though I spent quite a lot of time investigating the issue, I couldn't find a solution.

0
On

in order to prevent the MPMoviePlayerController from displaying UIAlertView alerts, you can use the following approach:

add the following methods to your application delegate, and make sure to call patchMPVVC only once on startup:

#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);
}

just keep in mind that this code might be rejected by apple due to the fact that it references the private MPVideoViewController class and _videoView_playbackErrorNotification method.