I have an mp4 file called lebron.mp4 in my Resources folder:
-(IBAction)videoButtonClicked:(id)sender{
NSString *url = [[NSBundle mainBundle]
pathForResource:#"lebron"
ofType:#"mp4"];
MPMoviePlayerViewController* moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
moviePlayerViewController.view.backgroundColor = [UIColor blackColor];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[moviePlayerViewController release];
}
Displays the movie player, but the movie doesn't play. Why?
did you try to display it like this :
[moviePlayerViewController play];
[window addSubview: MPMoviePlayerViewController.view];
?
Related
if (indexPath.row==0)
{
NSString *urlAsString = [[NSBundle mainBundle] pathForResource: [self.array objectAtIndex:indexPath.row] ofType:#"mov"];
NSURL *url = [NSURL fileURLWithPath:urlAsString];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:urlAsString];
[self.view addSubview:myPlayer.view];
[myPlayer.view setFrame:CGRectMake(0, 0, 320, 400)];
[myPlayer setFullscreen:YES animated:YES];
[myPlayer play];
}
i have one button in MPMoviePlayerController called done when i click on done button i need to come back to my tableview plz help me any one
MPMoviePlayerController *myPlayer declare global and init . and
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doneButtonClick:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
And selector method:
-(void)doneButtonClick:(NSNotification*)aNotification{
[myPlayer stop];
}
I want to implement the movie player for that,i'm using MPMoviePlayerViewController.
My code is,
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentModalViewController:moviePlayerController animated:YES];
[[moviePlayerController moviePlayer] play];
but it's continuously loading and not playing the video.What i'm wrong with my code.
My requirement is,
In the movie player,when i'm click on the done button it goes to the page which i'm starting from.
Thank you for your consideration and effort
Edit:
Any sample code for using MPMoviePlayerController instead of using MPMoviePlayerViewController please give me.(please give me your implemented sample code because i can't understand the tutorial code)please help me
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"aaa" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
i want a short video to play in my iphone app. When i use the code below, i only hear the audio and see
the regular view of the app. I want the video to play on top of this view.
What can i do about this?
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"LEADER" ofType:#"mov"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
Don't mix up MPMoviePlayerController and MPMoviePlayerViewController. When you use MPMoviePlayerController use it like this (typically for embedded videos on the iPad):
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
When you use MPMoviePlayerViewController then present the video with presentMoviePlayerViewControllerAnimated: (typically for fullscreen videos).
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view.frame = self.view.frame];
[self.view addSubview: player.view];
// ...
[player play];
The only magic that worked for me was
- (void) playMovie {
NSURL *url = [NSURL URLWithString:
#"http://www.example.com/video.mp4"];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.mc = controller; //Super important
controller.view.frame = self.view.bounds; //Set the size
[self.view addSubview:controller.view]; //Show the view
[controller play]; //Start playing
}
In Header file
#property (nonatomic,strong) MPMoviePlayerController* mc;
More Details
When I play a video doing this:
NSString *videoFilepath = [[NSBundle mainBundle] pathForResource:#"bacon" ofType:#"mov"];
NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath];
MPMoviePlayerController *movie;
movie = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[movie play];
on 3.2, it works pefeectly. But if I switch the base SDK to 4.0 i only hear the sound of the movie.
Any ideas?
I believe that adding this with your play command should improve matters for you:
[movie play]
[movie setFullscreen:YES];
[self.view addSubview:movie.view];
Try testing this property as it sounds like the movie is playing but has not been set to fullscreen:
http://developer.apple.com/iphone/library/documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/occ/instp/MPMoviePlayerController/fullscreen
This line of code is also of importance:
[self presentMoviePlayerViewControllerAnimated:movie];
try,
//add frame works
// AVFoundation.framework
// MediaPlayer.framework
[movie setFullscreen:YES];
[self.view addSubview:movie.view];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
moviePlayer.repeatMode = YES;
I want to play the video on iphone locally by storing the video in the app.
how can i do?
NSString *path = [[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
To store video in the app, you can just add it with a copy files phase in the build. For an example of how to play a movie, check out the Media Player docs and especially the MoviePlayer sample code.
Try the following code:
-(IBAction)Videoplay_btn:(id)sender
{
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *moviplayer =[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[moviplayer prepareToPlay];
[moviplayer.view setFrame: self.view.bounds];
[self.view addSubview: moviplayer.view];
moviplayer.fullscreen = YES;
moviplayer.shouldAutoplay = YES;
moviplayer.repeatMode = MPMovieRepeatModeNone;
moviplayer.movieSourceType = MPMovieSourceTypeFile;
[moviplayer play];
}
FYI
The MPMoviePlayerController class is formally deprecated in iOS 9.
(The MPMoviePlayerViewController class is also formally deprecated.)
To play video content in iOS 9 and later, instead use the
AVPictureInPictureController or AVPlayerViewController class from
the AVKit framework, or the WKWebView class from WebKit.