0

I have a UIViewController subclass called videoPlayerViewController. In storyboard I dragged out a UIViewController. I set the class correctly in Storyboard. I put a button on the screen. When I click the button, it executes the method playVideo:.

- (IBAction)playVideo:(id)sender
{
 NSURL *movieURL = [NSURL URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];

 MPMoviePlayerController *player =
 [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
 [player prepareToPlay];
 [player.view setFrame: self.view.bounds];  // player's frame must match parent's
 [self.view addSubview: player.view];
 [player play];
}

I get a black screen that does nothing.

This is the simplest version of the code I've had in this method over the last 6 hours.

I've tried every StackOverflow answer out there. I just want to play a video that I stream from the internet.

If I set:

player.movieSourceType = MPMovieSourceTypeStreaming;

the screen reads "loading" for a second, and then crashes. What exactly am I doing wrong?

I understand there are so many MPMoviePlayerController questions out there, and to just ask a general "How does it work" question seems ludicrous. I've been at this almost 6 hours now and no Google/Stack Overflow/Apple Documentation search has made this work.

4

1 回答 1

3

我使用了您提供的代码,但在创建后分配给播放器的头文件中创建了一个名为 mcp 的 MoviePlayerController 属性。这对我有用。电影加载并播放得很好。

在 .h 文件中:

@property (strong, nonatomic) MPMoviePlayerController *mcp;

在 .m 文件中:

- (IBAction)playVideo:(id)sender
{
    NSURL *movieURL = [NSURL     URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
    [player prepareToPlay];
    [player.view setFrame: self.view.bounds];  // player's frame must match parent's

    _mcp = player;

    [self.view addSubview: _mcp.view];
    [_mcp play];
}
于 2013-05-09T19:31:52.260 回答