MPMoviePlayercontroller not working in iphone SDK 4 ? - Help Needed - iphone

Till yesterday My MPMovieController was wokring fine in iPhone SDK 3 . But yesterday when I upgraded the SDK ti iphone SDK 4 my movieplayer stops working it is giving me a deprecation warning on the following line (They have deprecated lots of methods )
moviePlayer.movieControlMode = MPMovieControlModeDefault;
My full code is as follows :
NSURL *fileURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#/videos/%#",[[NSUserDefaults standardUserDefaults] objectForKey:#"SERVICE_URL"]
,customObject.movieURL]];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
if (mp)
{
// save the movie player object
self.moviePlayer = mp;
moviePlayer.movieControlMode = MPMovieControlModeDefault;
[mp release];
// Apply the user specified settings to the movie player object
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// Play the movie!
[self.moviePlayer play];
}
please Tell me which method to replace instead of the deprecated method or should do something different ?
Thanks ,

I used the MPMoviePlayerController just this morning and this code works good (tested on iPad simulator only)
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"video.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(50, 50, 200, 200);
[moviePlayer play];

Related

repeatmode doesn't work in MPMoviePlayerViewController?

How to display a recorded video as repeat as an'n' number of times like in Vine Application.
Here I use the MPMoviePlayerViewController, and works great display the recorded video. But the problem is, it doesn't repeating.
Here the currently using code is,
NSURL *url = [NSURL fileURLWithPath:videoPath];
playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
playerController.view.frame = CGRectMake(200, 402, 300, 200);
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[self.view addSubview: playerController.view];
[playerController.moviePlayer play];
NSLog(#"repeatMode: %d",playerController.moviePlayer.repeatMode);
[playerController.view addSubview:customview];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerController moviePlayer]];
And the NSNotification code,
- (void) movieFinishedCallback:(NSNotification*) aNotification
{
NSLog( #"myMovieFinishedCallback: %#", aNotification );
MPMoviePlayerController *movieController = aNotification.object;
NSLog( #"player.playbackState = %d", movieController.playbackState );
}
Can anyone please give the solution..
Note:
I'm using the XCode 4.5.2 tool and ios simulater 6.0
Try this code. It is working.
NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Video" ofType:#"mp4"]];
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
[moviePlayerController.moviePlayer prepareToPlay];
[moviePlayerController.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
[moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[self.view addSubview:moviePlayerController.view];
you can try this code
-(void) movieFinishedCallback:(NSNotification *) aNotification
{
if (aNotification.object == self.moviePlayer) {
NSInteger reason = [[aNotification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded)
{
[playerController play];
}
}
}
You have to keep the MPMoviePlayerController object as a member, otherwise the app would lose context to it and the movie will not loop.

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

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

Audio only with MPMoviePlayerController on iO4

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;

problem using MPMovieController in iPhone SDK 4.0

I was using MPMoviePlayer to play a short video in my app with no problems in SDK 3.1.3. I made the changes to the code in SDK 4 but the video is not playing. I just get a black screen and audio. The Apple Dev Center doesnt have any sample code for this class for the latest SDK. Following is the code I'm using:
- (void)viewDidLoad {
[super viewDidLoad];
//videoPlayer is a MPMoviePlayerController object defined in the header file of the view controller
if (videoPlayer == nil){
NSString * videoPath = [[NSBundle mainBundle] pathForResource:#"myvideo" ofType:#"mp4"];
if (videoPath == NULL){
return;
}
NSURL * videoURL = [NSURL fileURLWithPath:videoPath];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
videoPlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:#"MPMoviePlayerPlaybackDidFinishNotification" object:movieController.moviePlayer];
[videoPlayer play];
[videoPlayer setFullscreen:YES];
[self.view addSubview:videoPlayer.view];
}
}
The above results in just the audio being played with a black screen. The notification is called correctly at the end of the playback.
When the above did not work, then I even tried using the new MPMoviePlayerViewController class as follows:
- (void)viewDidLoad {
[super viewDidLoad];
NSString * videoPath = [[NSBundle mainBundle] pathForResource:#"myvideo" ofType:#"mp4"];
if (videoPath == NULL){
return;
}
NSURL * videoURL = [NSURL fileURLWithPath:videoPath];
//movieController is an MPMoviePlayerViewController object defined in the header file of view controller
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:#"MPMoviePlayerPlaybackDidFinishNotification" object:movieController.moviePlayer];
[movieController.moviePlayer setFullscreen:YES];
[movieController.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:movieController];
}
Same problem persists - I can hear the audio and the notification at the end of the playback is called as expected. However I just see a black screen instead of the video.
There is nothing wrong in the encoding of the video because the same video plays fine in iTunes as well as on my iPod Touch in the regular videos playlist.
Could anyone help me out with this problem?
Thanks in advance
problem solved - for the benefit of those who are stuck on a similar issue, the solution is to explicitly create the frame for the view of the MPMoviePlayerController as follows:
I changed the lines:
[videoPlayer play];
[videoPlayer setFullscreen:YES];
[self.view addSubview:videoPlayer.view];
to the following:
[videoPlayer prepareToPlay];
[videoPlayer play];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0.0, 0.0, 480.0, 320.0); //this is explicitly added and solves the problem