문제

I want to play a video in the iPhone simulator. I have tried with MPMoviePlayerViewController, but its not playing. Anybody has an idea on how to do it ? If there is any good tutorial , please help me find one. Thanx.

NOTE: Question related to MPMoviePlayerViewController not MPMoviePlayerController

도움이 되었습니까?

해결책

Just drag and drop the video file in Your Xcode project

Give the url of video in "videourl"

NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];     
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];

It will run perfectly in simulator

This link Can also help You

다른 팁

Assuming ARC.

You can for example call that in your viewDidLoad method and add that controller to your view using:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];

   [self.view addSubview:theMovie.view];
    [self addChildViewController:theMovie];
}

in my header file I write:

MPMoviePlayerController *moviePlayer;

with this property:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

and in the method in which I init the moviePlayer:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;

Use the following code

MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];

moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:moviePlayer1];
[moviePlayer1 play];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top