开发者

Using UIViewController MediaPlayer additions in iPhone 4

开发者 https://www.devze.com 2023-01-09 04:18 出处:网络
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 presentMov

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 U开发者_Python百科RLWithString: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];
}


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.


if these additions are in a static library then you need to make sure your main project has additional linker flags set, otherwise the compiler will ignore the extensions.

go into your build settings for your main project, and under linker flags make sure you have the following set:

-ObjC -all_load

0

精彩评论

暂无评论...
验证码 换一张
取 消