I want to add MPMoviePlayerController to a UIView.
first, I put a view in xib file, named youTubeView. youtubePlayer is the MPMoviePlayerController.
[youtubePlayer.view setFrame:youTubeView.frame];
[youTubeView addSubview:youtubePlayer.view];
[youtubePlayer play];
I want the view of youtubePlayer overlay on youTubeView. but the view of youtubePlayer goes wide, it just overlay a part of youTubeView. why ?
Try this
[youtubePlayer.view setFrame:youTubeView.bounds];
[youTubeView addSubview:youtubePlayer.view];
[youtubePlayer play];
Just assign the scaling mode for the movie like this youtubePlayer.scalingMode = MPMovieScalingModeFill;
This will solve your problem.
Happy Coding:)
Related
I have an app with a news feed screen, like the one in the facebook app. For this, I have made a custom cell, which has a contentView which is a UIView. This contentView gets initialized for displaying text, an image or video. This is done in the class for the custom cell. For the video, I'm trying to add MPMoviePlayerViewController as a subview to the cell's contentView:
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:nil];
player.view.frame = self.contentView.frame;
player.view.tag = kVideoView;
[self.contentView addSubview:player.moviePlayer.view];
Then, when I load that cell in the tableviewcontroller, I want to give it contentURL, like this:
MPMoviePlayerViewController *controller = (MPMoviePlayerViewController *)[cell viewWithTag:kVideoView];
controller.moviePlayer.contentURL = [NSURL URLWithString:postInfo.uri];
return;
This crashes the app with an error:
-[MPMovieView moviePlayer]: unrecognized selector sent to instance
How do I fix this?
As you are adding player.moviePlayer.view to content view.
So while retrieving you will get reference to player.moviePlayer.view only not MPMoviePlayerViewController.
My suggestion is don't create multiple MPMoviePlayerViewController instance. You can add some UIButton or UIImageView on cell with snapshot of particular video. And while playing only you can create MPMoviePlayerViewController instance and play your video
I want to add Video file in my iPad application.
I have use MPMoviePlayerController for this it work fine.
but i have one problem this controller is covering hole WINDOW of iPad.
I want my UIViewController should contain one textView, Navigation Bar, one Running Video file,
and four UIButton. Have can i achive this?
You can done this by add that MPMoviePlayer as subView of your view, means addSubview on your view with fix frame.
like this,
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // myView is your parent view which hold your player
[myView addSubview: player.view];
[player play];
For more references check this.
I have an app that is purely a Tab Bar Controller with 5 tabs (views). I want those views to be portrait only. However, the app does allow video clips to be played and uses an MPMoviePlayerViewController to do so. But I can't get the player to rotate to landscape!
I have tried the following (along with a lot of other things):
Subclassing MPMoviePlayerViewController and overriding the shouldAutorotateToInterfaceOrientation method for that class.
Allowing the app to have landscape orientation, then attempt to lock the tab views to portrait (doesn't lock them, allows them to go to landscape which I don't want).
I have scoured StackOverflow and Google for days now!
Anyone familiar with this issue and how to get the movie player to rotate???
try implementing UIViewController containment. Designate the viewController of the tab that you are showing the movie in as the parent (or container) viewController.
You will want to override shouldAutorotateToInterfaceOrientation in the subclass to only allow landscape, which it sounds like you already have done. In your parent view controller and the tabBarController you will want to make sure that they are forwarding the autorotate methods to your subclass. You can check this by putting an NSLog in your subclasses implementation of shouldAutorotateToInterfaceOrientation.
Then, when you want to show the video, add a subclass of MPMoviePlayerViewController to it.
When you load your subclass of the movies player, try doing this in the parent view controller:
[self addChildViewController:self.subclassedMoviePlayerViewController];
[self.view addSubview:self.currentViewController.view];
[self.subclassedMoviePlayerViewController didMoveToParentViewController:self];
or if you want to animate the change you can do something like this:
CGRect viewFrame=self.subclassedMoviePlayerViewController.view.frame;
CGFloat viewHeight=inputViewFrame.size.height;
CGRect newFrame=CGRectMake(0, self.view.frame.size.height, viewFrame.size.width, viewFrame.size.height);
self.subclassedMoviePlayerViewController.view.frame=newFrame;
[self addChildViewController:self.subclassedMoviePlayerViewController];
CGRect offSetRect=CGRectOffset(newFrame, 0, -inputViewHeight);
[self.view addSubview:self.subclassedMoviePlayerViewController.view];
[UIView animateWithDuration:0.2
animations:^{
self.subclassedMoviePlayerViewController.view.frame=offSetRect;
}
completion:^(BOOL finished){
[self.subclassedMoviePlayerViewController didMoveToParentViewController:self];
}];
Of course you will have to set the frame for the view for the subclass of the movies player view controller before you add it.
then when you want to remove it:
[self.subclassedMoviePlayerViewController willMoveToParentViewController:nil];
[self.subclassedMoviePlayerViewController.view removeFromSuperView];
[self.subclassedMoviePlayerViewController removeFromParentViewController];
Good luck
t
Finally solved this!
Ok so there is an important method that must be overwritten in the parent view controller (in my case, the tab view's controller):
-(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
return NO;//This must be NO to allow any child views to use their own orientation
}
And then in the MPMoviePlayerViewController I subclassed, set this for the orientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;//This allows all orientations, set it to whatever you want
}
Then I present the MPMoviePlayerViewController like this from the tab view controller:
- (IBAction)buttonVideo:(id)sender {
MovieViewController *vc = [[MovieViewController alloc] initWithContentURL:#"http://www.MY-VIDEO-URL.com"];
[self presentMoviePlayerViewControllerAnimated:vc];
}
And WA-LA! A movie player that allows all orientations within a portrait locked, tab bar application!
Starting with this code:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieLink];
The next thing I need to do is set the player's frame and add its view as a subview. But I want it to go immediately to fullscreen, and I want it to be on top of everything else. What is the best way to do that?
If I do something like this:
[self.view addSubview:player.view];
The player does a weird resizing thing, then jumps to fullscreen. I know this is the last step:
[player setFullscreen:YES animated:NO];
But where can I add the player's view so that I don't see any weird clipping or resizing? Do I use [UIScreen mainScreen] somehow? Or access the main window of the app?
I have successfully put a MPMoviePlayerController in a UIPopoverController by doing:
NSString *filenameString = [NSString stringWithString:[[helpVideosArray objectAtIndex:tagNumber] objectForKey:VIDEO_FILE_NAME]];
HelpVideoPopover *helpVideoPopover = [[HelpVideoPopover alloc] initWithVideoFilename:filenameString PreviewFrameView:self];
currentPopover = [[[[UIPopoverController alloc] initWithContentViewController:helpVideoPopover] retain] autorelease];
[currentPopover setPopoverContentSize:CGSizeMake(320, 240)];
[currentPopover presentPopoverFromRect:((UIButton*)sender).frame inView:previewView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
currentPopover.passthroughViews = [NSArray arrayWithObject:((HelpVideoPopover*)[currentPopover contentViewController]).movieController.view];
The problem is that when the user wants to view the video fullscreen(and I allow that) that the popover view is on top of the fullscreen video. So my question is that is there another I'm supposed to be doing this. Or maybe when I display the popover I just use a blank one and overlay a movie player on top of it from the parent view controller? I would really like to keep the movie player logic inside the popover view controller though.
Without knowing the details of your application i would imagine you could do this in several ways.
You could either open the video in a fullscreen modal view - This would cover the popover.
If you're displaying the fullscreen video in the detail-view behind the popover, then you could do something as simple as just hiding the popover once the fullscreen video has been shown.