Not able to play a video in ios6 - iphone

I'm not able to play the video using MPMoviePlayerController, this is my code
NSString *url = [[NSBundle mainBundle] pathForResource:#"MLL_Video"ofType:#"mp4"];
MPMoviePlayerController *theMoviPlayer;
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
theMoviPlayer.scalingMode = MPMovieScalingModeFill;
theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
self.myPlayer=theMoviPlayer;
[self.view addSubview:self.myPlayer.view];
[self.myPlayer prepareToPlay];
[self.myPlayer play];
But it does not work even used the following code also:
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
moviePlayer.view.frame = self.view.frame;
moviePlayer.moviePlayer.shouldAutoplay=YES;
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer.moviePlayer setFullscreen:YES animated:YES];
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];
But it also does not work, seems to be some bug in latest xcode(4.4), Please share if any body has a solution on this.

Related

iOS : Playing remote video with URL with MPMoviePlayerController

NSURL *url= [NSURL URLWithString:#"http://www.dailymotion.com/video/x109z02"];
MPMoviePlayerController *theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
theMoviPlayer.scalingMode = MPMovieScalingModeFill;
theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
[self.view addSubview:theMoviPlayer.view];
[self.theMoviPlayer play];
framework is also addded and imported in .h file but video is not playing in iphone (internet connection is also ok)
NSURL *url = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
Use the UIWebView , a very simple and easy way.

MPMoviePlayerController loadState doesn't switch to MPMovieLoadStatePlayable

I have a MPMoviePlayerViewController to play Movies in fullscreen. I checked the movies they play fine via Quicktime.
The Problem is, that using the MPMoviePlayerViewController (Simulator and device) the Movie doesn't start playing(it's a video that is stored locally on the iPad btw).
NSString *path = [[NSBundle mainBundle]pathForResource:resource ofType:#"mov"];
self.mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];
[self.mpviewController.moviePlayer prepareToPlay];
self.mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.mpviewController.moviePlayer.controlStyle = [self presentModalViewController:self.mpviewController animated:YES];
NSLog(#"%d",self.mpviewController.moviePlayer.loadState);
[self.mpviewController.moviePlayer play];
Any Ideas what I am missing ?
tia
well, I dont know what it was. I ended up writing a new view controller with this code - that worked:
NSURL *url = [NSURL fileURLWithPath:self.urlPath];
self.playerController = [[MPMoviePlayerController alloc] initWithContentURL: url];
CGRect bounds = CGRectMake(0, 0, 1024, 748);
self.playerController.scalingMode = MPMovieScalingModeNone;
[self.playerController.view setFrame:bounds];
[self.view addSubview:self.playerController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullscreenCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playerController];
self.playerController.controlStyle = MPMovieControlStyleFullscreen;
[self.playerController setFullscreen:YES animated:YES];
[self.playerController play];

Playing video in my iPhone application (MPMoviePlayer)

I am using the code below to attempt to play a video in my iPhone app. However, I don't understand why it doesn't work.
NSURL *url = [NSURL fileURLWithPath:filePath];
MPMoviePlayerController* moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:url] autorelease];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
Where is your play statement ??
[moviePlayer play];

MPMoviePlayerViewController Issue-Iphone

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

Playing a video in iOS app: audio but no picture

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