Question

i have used MPMoviePlayerController to play a video but this only shows the black screen. not played my video. this code is correct. where may i wrong....

i have done this code to play video..

    NSString * str=[[NSBundle mainBundle]pathForResource:@"iGreet" ofType:@"m4v"];
    NSURL * url=[NSURL fileURLWithPath:str];
    MPMoviePlayerController * movieController=[[MPMoviePlayerController alloc]initWithContentURL:url];
    movieController.controlStyle=MPMovieControlStyleFullscreen;
    [movieController.view setFrame:self.view.bounds];
    [self.view addSubview:movieController.view];
    [movieController prepareToPlay];
    [movieController play];

Any help appreciated.. Thanks in advance..

Was it helpful?

Solution

If you are trying to play video from resource then you need mentioned this:

   [movieController setMovieSourceType:MPMovieSourceTypeFile];

OTHER TIPS

This is my code. I have a button that show image an image for my video.

@property (nonatomic,strong) MPMoviePlayerController* moviePlayer;

add this to your .h file.

NSURL *url = [NSURL URLWithString: @"http://www.mydomain/video/1.mp4"];

_moviePlayer =  [[MPMoviePlayerController alloc]
                 initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:_moviePlayer];
CGRect frame = _btnVideo.frame;
[_moviePlayer.view setFrame:frame];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:NO animated:YES];

As per documentation, .m4v extension is not mentioned to play.

enter image description here

I did like this and it works fine:

NSString *videoFileName = [[NSBundle mainBundle] pathForResource:videoName ofType:@"m4v" inDirectory:nil];

self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:videoFileName]];
[self.moviePlayerController setShouldAutoplay:YES];
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController setFullscreen:NO];
[self.moviePlayerController.view setFrame:self.infoViewController.view.bounds];
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController play];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top