Jackelope11
Jackelope11

Reputation: 1171

How do you play a video in your app?

I have a video saved in my xcode project that I want to play as a response to a button click. Does IOS have built in media API's to handle that? Could anyone give the class name that handles video on the iPhone?

Upvotes: 1

Views: 277

Answers (3)

Francesco Puglisi
Francesco Puglisi

Reputation: 2177

Here's some code to get you started:

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"yourfilename" ofType:@"m4v"]]];
        [[moviePlayerController view] setFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
        [moviePlayerController setShouldAutoplay:NO];
        [moviePlayerController setControlStyle:MPMovieControlStyleEmbedded];
        [[moviePlayerController backgroundView] setBackgroundColor:[UIColor clearColor]];
        [moviePlayerController prepareToPlay];

By the documentation you have to set the MPMoviePlayerController's frame with a frame as big as the parent view's.

Upvotes: 1

Rayfleck
Rayfleck

Reputation: 12106

MPMoviePlayerViewController. Please search a little bit before asking questions.

Upvotes: 1

Joris
Joris

Reputation: 6306

Yes iOS does contain media API's to handle that.

Upvotes: 0

Related Questions