user1366911
user1366911

Reputation: 917

MPMoviePlayerController shows blank screen or crashes app

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.

Upvotes: 0

Views: 2258

Answers (1)

Indi
Indi

Reputation: 544

I used your provided code but created a MoviePlayerController property named mcp in the header file that I assigned to player to after creating it. That worked for me. The movie loaded and played just fine.

In the .h file:

@property (strong, nonatomic) MPMoviePlayerController *mcp;

In the .m file:

- (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];
}

Upvotes: 3

Related Questions