views:

249

answers:

1

I want to use the UIViewController MediaPlayer additions in an iPhone 4 static library.

The .h of my view controller subclass imports <MediaPlayer/MediaPlayer.h>. However, when I use presentMoviePlayerViewControllerAnimated in the .m I get a compiler warning:

'MyViewController' may not respond to '-presentMoviePlayerViewControllerAnimated:animated:'

What am I doing wrong? How do I avoid this warning? Does the static library have anything to do with this?

Current code:

NSURL* url = [NSURL URLWithString:urlAsString];
if ([MPMoviePlayerController instancesRespondToSelector:@selector(setFullscreen:animated:)]) {
    // iPhone 3.2 or higher  
    MyMoviePlayerViewControllerSubclass* vc = [[MyMoviePlayerViewControllerSubclass alloc] initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:vc animated:YES];
    [vc release];
}
A: 

presentMoviePlayerViewControllerAnimated: takes a parameter of type MPMoviePlayerViewController.

Here is an example:

// Initialize a movie player object with the specified URL
    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    if (mp) {
        // save the movie player object
        self.moviePlayerViewController = mp;
        [mp release];

        //Present       
        [self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController];

        // Play the movie!
        self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
        [self.moviePlayerViewController.moviePlayer play];
    }

Where url is the url of the movie, and self.moviePlayerViewController is a property var (if you need one) of type MPMoviePlayerViewController.

Calvin L
I'm passing an instance of a MPMoviePlayerViewController subclass. Is that the problem?
hgpc
That should be fine -- are you using the iOS 4 SDK?
Calvin L
Yes. The Base SDK is iPhone Device 4.0 and the iPhone OS Deployment Target is iPhone OS 3.1.
hgpc
Where are you calling `presentMoviePlayerViewControllerAnimated`? Maybe you should post some code so we can see what's going on more clearly.
Calvin L
Posted code and clarified that it's a static library.
hgpc