views:

139

answers:

2

Hi everyone!

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 recommend me how to prevent this from happening?

Thanks in advance!

+1  A: 

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 tough I spent quite a lot of time investigating the issue I couldn't find a solution.

samsam
Me too. I gave up with it:(. In my app, I have better ways to inform alerts/errors but now I have to accept this inconsitency
vodkhang
yep, try filing a "bug" or feature request at apples developer site. maybe that helds for future releases.
samsam
+1  A: 

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.

dormin
+1 for trying with private API
vodkhang