My iPhone Video Only Plays in Portrait Mode - iphone

I am using MPMoviePlayerController to play a movie. The movie starts in portrait mode (as that's the only mode the app uses) and stays there even if the device is rotated. I never explicitly set the shouldAutoRotateetc. function to respond to landscape and portrait because I don't want my views resizing. Is there a way to get the video to respond to portrait and landscape rotations? Any help would be greatly appreciated.
FYI: Here is my code
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"TestMovie" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
//Listen so we can clean up after the movie is over
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController setFullscreen:YES animated:YES];
[moviePlayerController play];

Hmm. OK. Figured it out a half-hour after I was stumped.
There is apparently now an MPMoviePlayerViewController that handles all that. Here's my new updated code:
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
This will allow it to respond to rotation events, etc. Nice!

Related

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

Adjust AVPlayer Frame Rate During Playback [duplicate]

I'm wondering if it's possible to change the video playback speed in an iphone application. we want users to yell in the microphone to speed up the playback and get to the end.
You have to use setCurrentPlaybackRate:
There is a rate property for the AVPlayer.
If you take the example from Apple called "avPlayerDemo" in the resource section, you then simply have to set the mplayer.rate. It worked for me, I created a new slider in the xib files, implemented that slider in the AVPlayerDemoPlaybackViewController and simply set mPlayer.rate to the slider value.
What about the MPMoviePlayerController?
setCurrentPlaybackRate
Here's some code which does not work at that spot
-(IBAction)abspielen:(id)sender
{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:titleOfButton ofType:#"mov"];
NSURL *movieURL = [ NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc]initWithContentURL: movieURL];
[themovie play];
[themovie setCurrentPlaybackRate:2.f];
[themovie release];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer release];
}

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

MPMoviePlayercontroller not working in iphone SDK 4 ? - Help Needed

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