MPMoviePlayerController view orientation differs on iphone 3g and 4g - objective-c

I'm trying to play fullscreen landscape video in .m4v format on iPhone using MPMoviePlayerController in my cocos2d game. On 4g device everything works well, but on 3g the video has screen dimensions but vertical orientation, so I can only see the left side of the movie. I'm not sure if the problem is with MPMoviePlayerController or with cocos2d gl view. Here's my code:
NSString *url = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"m4v"];
player = [[[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:url]] retain];
[player.view setFrame: [[CCDirector sharedDirector] openGLView].bounds];
if ([player respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
player.controlStyle = MPMovieControlStyleNone;
player.shouldAutoplay = YES;
CGSize winSize = [[CCDirector sharedDirector] winSize];
CGRect rScreen;
rScreen.origin.x = 0;
rScreen.origin.y = 0;
rScreen.size.width = winSize.width;
rScreen.size.height = winSize.height;
player.view.frame = rScreen;
} else {
// Use the old 2.0 style API
player.movieControlMode = MPMovieControlModeHidden;
}
[[[CCDirector sharedDirector] openGLView] addSubview:player.view];
[player play];
How to make video play well on 3g device? Thanks for your help!

Related

iOS 7 Video not playing MPMoviePlayerController

This code is working perfect in iOS 8 . but unable to play video in iOS7.The player shows up but plays nothing.Thanks
NSString *url = #"http://.../playlist.m3u8";
NSURL *streamURL = [NSURL URLWithString:url];
self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
self.streamPlayer.controlStyle= MPMovieControlStyleFullscreen;
self.streamPlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.streamPlayer.shouldAutoplay = YES;
[self.view addSubview:self.streamPlayer.view];
[self.streamPlayer prepareToPlay];
[self.streamPlayer play];
From the documentation:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
Try to set the frame of your video player.

MPMoviePlayerController error _itemFailedToPlayToEnd while playing RTMP video link iOS 7

I am trying to play a video like:
- (void) playMovie {
NSURL *url = [NSURL URLWithString:
#"rtmp://122.129.75.174:61935/live/peghamtvX007"];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.videoController = controller; //Super important
controller.view.frame = self.view.bounds; //Set the size
[self.view addSubview:controller.view]; //Show the view
[controller play]; //Start playing
}
But it failed to play. Here is error:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
Can i play rtmp link in WebView using MPMoviePlayerController? and also help me out in this error.

EXC_BAD_ACCESS when movie played the second time

I am using mpmovieplayercontroller to play a movie in my game. When the user taps the screen I run a method that replaces the current layer containing the movie with the game main menu. It works fine the first time, but when I try to play the video the second time from the main menu I get an EXC_BAD_ACCESS error on the line
int retVal = UIApplicationMain(argc, argv, nil, #"AppController");
in the main.m.
Please find the relevant code below.
-(void)playVideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"movie" ofType:#"mp4"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.repeatMode = MPMovieRepeatModeOne;
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
// This does blows up in cocos2d, so we'll resize manually
[moviePlayer setFullscreen:YES animated:YES];
CGSize winSize = [[CCDirector sharedDirector] winSize];
moviePlayer.view.frame = CGRectMake(0, 0, winSize.width, winSize.height); //width and height are swapped after rotation
[[[CCDirector sharedDirector] view] addSubview:moviePlayer.view ];
[moviePlayer play];
UITapGestureRecognizer * tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tapGestureRecognizer.delegate = (id)self;
tapGestureRecognizer.numberOfTapsRequired = 1;
[[[CCDirector sharedDirector] view] addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
} else {
// Use the old 2.0 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer play];
}
}
- (void)handleTap:(UITapGestureRecognizer *)gesture {
[moviePlayer stop];
[[MenuManager sharedMenuManager] runMenu:kMMenuLayer];
}
// this enables you to handle multiple recognizers on single view
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
-(void)moviePlayBackDidFinish:(NSNotification*)notification {
moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// If the moviePlayer.view was added to the openGL view, it needs to be removed
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
CCLOG(#"this block is okay");
}
[moviePlayer release];
}
Please help.
The reason why you're getting the message is sent to a deallocated instance is because you've not removed the tapGestureRecognizer from the view. I believe your MenuManager singleton replaces the current layer with another, but since the tapGestureRecognizer is still part of the view it will try to access the handleTap, which by this time is deallocated. Add the following line before singleton call in handleTap.
[[[CCDirector sharedDirector] view] removeGestureRecognizer:tapGestureRecognizer];

Adding CCLayer over a View playing video using MPMoviePlayerController?

I have created a View which plays video using MPMoviePlayerController. Now I wish to show a CCLayer over/overlapping this View while the video is in action. How to move forward with this?
//This is where you give path of your video and init it.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"video_file_name" ofType:#"mp4/mov"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
NSLog(#"%f", [[CCDirector sharedDirector] view].frame.size.width);
moviePlayer.view.frame = [[CCDirector sharedDirector] view].frame;
[[[CCDirector sharedDirector] view] addSubview:moviePlayer.view];
[[[CCDirector sharedDirector] view] bringSubviewToFront:moviePlayer.view];
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self // the object listening / "observing" to the notification
selector:#selector(playbackComplete:) // method to call when the notification was pushed
name:MPMoviePlayerPlaybackDidFinishNotification // notification the observer should listen to
object:moviePlayer]; // the object that is passed to the method
//[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainMenu scene] withColor:ccWHITE]];
}
//This is where you define what happens once the playback is complete
-(void)playbackComplete:(id)sender {
// [(MPMoviePlayerController *)sender stop];
// ((MPMoviePlayerController *)sender).view.hidden=YES;
// [((MPMoviePlayerController *)sender) removeFromParentAndCleanup:YES];
[moviePlayer.view removeFromSuperview];
//This is where you load another scene(Ex: Image, Animation etc)
NSLog(#"Make transition");
CGSize size = [[CCDirector sharedDirector] winSize];
[[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.0 scene:[GameLayer scene] ]];
}

MPMoviePlayerViewController not showing volume slider?

I am playing the video from the url:
MPMoviePlayerViewController *m = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
if([m.moviePlayer respondsToSelector:#selector(setAllowsAirPlay:)])
m.moviePlayer.allowsAirPlay = YES;
[self presentMoviePlayerViewControllerAnimated:m];
It is playing, but there is no volume control slider. Is it possible to add volume control?
You can use MPVolumeView object.
volume = [[MPVolumeView alloc] initWithFrame: rect];
[self addSubview:volume];