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.
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 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:)
I have an iPad app that has a movie preview view in the top half of the screen and thumbnails in the bottom half of the screen. When the user taps a thumbnail that movie starts playing in the movie preview view using a MPMoviePlayerViewController with control style MPMovieControlStyleEmbedded. The embedded style has the built in functionality of allowing the user to tap a fullscreen button to show the movie in fullscreen.
All of the above functionality works great but I want to always show a watermark over movies in the preview and fullscreen views. The watermark shows correctly in the preview view when I add a label to vcMoviePlayer.view but I cannot get that label to show over the movie in fullscreen mode after the fullscreen button has been pressed. I'm adding the label to vcMoviePlayer.view (making sure to bring the label to the front) when the movie player sends the MPMoviePlayerDidEnterFullscreenNotification but it still does not appear. Has anyone else seen this behavior? Does anyone know how to get a view to appear over a movie playing in fullscreen after the fullscreen button has been tapped? I've burned a lot of time trying to figure this out and any help is very very appreciated. Thanks!
I use this code and works on iOS 5 and iOS 6
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
UIView * videoView = [[window subviews] lastObject];
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,100.0f,100.0f)];
[videoView addSubview:customView];
On iOS 5 you have to remove the customView on MPMoviePlayerWillExitFullscreenNotification
When in fullscreen mode, MPMoviePlayerController does not use the supplied superview anymore but directly displays itself on the current (key) window.
For finding something you can put your view/s on once the player is in fullscreen mode, do as follows:
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (!window)
{
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
Now you can put your custom views on top of that window and it will be visible while MPMoviePlayerController is being in fullscreen mode.
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
100.0f,
100.0f)];
[window addSubview:customView];
For finding the right moment to add/remove your custom views, register the following notifications and do it within the registered handlers:
MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification
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.