UINavigationController hides AVPlayerViewController progress slider - ios

I'm using AVPlayerViewController with the UINavigationController like following code.
AVPlayerViewController* audioPlayer = [[AVPlayerViewController alloc] init];
audioPlayer.audioFilePath = recordFilePath;
[self.navigationController pushViewController:audioPlayer animated:YES];
When the AVPlayerViewController appeared, the progress slider had been hidden by the UINavigationBar control.
How can I show the progress slider along with the UINavigationBar?

Try to set the navigation bar's translucent property to "NO" in your viewDidLoad
self.navigationController.navigationBar.translucent = NO;
It will start the view from being framed underneath the navigation bar and status bar. Hence you can see AVPlayerViewController progress slider.

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
[self performSelector:#selector(PlayVideo) withObject:self afterDelay:1.0];
}
-(void)PlayVideo
{
NSURL *videoURL = [NSURL URLWithString:#"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self.navigationController pushViewController:playerViewController animated:YES];
}
The progress slider will shown at the bottom of the device

Related

How to hide top bar on QLPreviewController by default

I am presenting a QuickLook preview controller like so:
QLPreviewController *qlController = [[QLPreviewController alloc] init];
qlController.dataSource = self;
qlController.delegate = self;
dispatch_async(dispatch_get_main_queue(), ^{
[rootVC presentViewController:qlController animated:NO completion:nil];
});
I'm passing it a usdz preview item. As soon as the item loads in the top bar it disappears but the effect is jarring.
Is there any way to hide this top bar (highlighted in yellow) by default so it never shows up?
Yes you can, but after presenting QLPreviewController. Following code will works to hide navigation bar, but after few moment.
Objective-C:
[self presentViewController:qlController animated:true completion:^{
UINavigationBar *navBar = [[[[[qlController view] subviews] firstObject] subviews] objectAtIndex:1];
[navBar setHidden:true];
}];
Swift:
self.present(qlController, animated: true) {
if let navigationBar = qlController.view.subviews.first?.subviews[1] as? UINavigationBar {
navigationBar.isHidden = true
}
}

MPMoviePlayerController gives me a black empty view on BACK button

I have used MPMoviePlayerController to play video in my web view from a live url
but when i pop the view controller so at that time the black screen appears in the view and the navigation bar title changes as it should be.
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *movieURL = [NSURL URLWithString:self.url];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.contentURL = movieURL;
if (self.moviePlayer)
{
[self.moviePlayer prepareToPlay];
self.moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
// save the movie player object
[self.moviePlayer setFullscreen:YES];
[self.moviePlayer setShouldAutoplay:YES];
[self.moviePlayer setAllowsAirPlay:YES];
// Play the movie!
[self.moviePlayer play];
[self initializeNavigationController];
}
}
-(void)initializeNavigationController
{
UIBarButtonItem *buttonBack = [[UIBarButtonItem alloc] backButtonWithtarget:self action:#selector(Back)];
self.navigationItem.leftBarButtonItem = buttonBack;
}
-(void)Back
{
[self.moviePlayer.view removeFromSuperview];
[self stopLoadingVideoInView];
[self.navigationController popToRootViewControllerAnimated:YES];
}
Live video screen
After Back button press
I think you just remove [self.view removeFromSuperview]; and replace with
[self.moviePlayer.view removeFromSuperview];
I solved it finally
In app delgate i created a method to allocate memory to vc again
- (void)resetAppToFirstController
{
UIViewController *obj = [[MainMenuViewController alloc] init];
//Create Navigation Controller to Hold View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self.window setRootViewController:navigationController];
}
and on my back button action
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.resetAppToFirstController;
This solved my issue it may help some one for MPMoviePlayer
In case you are added youMovieController as sub view of parent view, use this method to remove it.
[self.view removeFromSuperView]
In case you are pushing viewController via UINavigationController, just call this to go back.
[self.navigationCotroller popViewController:animated]
In case you are present ViewController, use this to remove it.
[self dismissViewController]
remove [self.view removeFromSuperview]; and replace with [self.moviePlayer.view removeFromSuperview];
- (void)resetAppToFirstController
{
UIViewController *obj = [[MainMenuViewController alloc] init];
//Create Navigation Controller to Hold View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self.window setRootViewController:navigationController];
}

How can I play movies on the toppest screen in IOS?

I am trying to play movies from a view controller. I am using the code below to do that:
VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:#"videoPlayerController"];
moviePlayer.view.frame = rect;
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[window.rootViewController presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:items];
Normally it works fine. But sometimes, movie starts but I cannot see the video, just I can hear the sounds.
What is the best way to play video on top of everything?
NSString *path = [[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Another solution would be to segue to another ViewController and dissmiss it when the movie ends.
You can also try using AVPlayer. In that case, you can play the video in your current view itself without having a separate overlay for the video.
Here's an example of playing multiple AVPlayers. You can modify the code to play a single video.

How to change the bar color in UIImagePicker?

I am trying to color the bars in the camera view black. None of the below approaches worked so far. There are 2 views that I want to change, the first with the camera icon and "cancel", the second with the "retake" and "use" buttons. Any ideas?
- (void)openCamera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.toolbar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.tintColor = [UIColor blackColor];
[self presentModalViewController:picker animated:NO];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIImagePickerController *picker = (UIImagePickerController *)navigationController;
if((picker)&&(picker.sourceType == UIImagePickerControllerSourceTypeCamera))
{
picker.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.tintColor = [UIColor blackColor];
}
}
You might have some luck using UIAppearance. Look up the documentation.
You can use the UIImagePickerController showsCameraControls and cameraOverlayView to use a custom view over the UIImagePickerController. Setting the showsCameraControlsvalue to NO will hide everything on the UIImagePickerController but the camera view. cameraOverlayView allow you to put your own view over the camera view. You can then create a view with your own bottom bar, your own buttons, ... and put it in front of the UIImagePicker.
UIView *overlayView = [[UIView alloc] init];
/* Customize overlayView with your bottomBar and button */
UIImagePickerController imagePickerController = [[UIImagePickerController alloc] init];
/* Configure your UIImagePickerController for picture and/or video */
imagePickerController.showsCameraControls = NO; //Must be set to NO if you want to use the cameraOverlayView
imagePickerController.cameraOverlayView = overlayView;
overlayView = nil;
Unfortunately, with this method you must recreate all the buttons of the original UIImagePickerController view (the flash mode button, the options button, ...) if you want to use them, and you have to create your own navigation controller to go to the view with the "retake" and "use" buttons. However it's very simple to implement.

MPMoviePlayerViewController Hide Status Bar

I have an iPad application that creates and shows a video with an MPMoviePlayerViewController. Here's my code:
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:URLEncode(uri)]];
[mpvc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[mpvc setWantsFullScreenLayout:YES];
[<MainViewController> presentModalViewController:mpvc animated:YES];
Movie load/playback works fine, however, when the Movie Controller appears, it shows the status bar (connection, battery, hour) at the top, even when I have it deactivated on my main window.
I've tried doing:
[mpvc setWantsFullScreenLayout:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And nothing seems to work, HOWEVER if I also put:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
The status bar disappears! But the Movie Controller still gets resized as if the status bar is there (even when I already used -setWantsFullScreenLayout:).
Can someone point me to an easy (proven) way to show the video without the status bar?
Thanks.
Just realised the question was iPad-specific. My code was for the iPhone, but some of it may help you anyway.
I had to do this a couple days ago, I think your issue is simply not calling hide on the status bar after the video starts playing. Either way I have the tried and tested code here which works from 3.0 to 4.2:
- (IBAction) playIntroVideo
{
NSString *videoString = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
_player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
if
(
[_player respondsToSelector:#selector(view)] &&
[_player respondsToSelector:#selector(setFullscreen:animated:)] &&
[_player respondsToSelector:#selector(setControlStyle:)]
)
{
[[_player view] setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT_FULL)];
[_player setFullscreen:YES animated:YES];
[_player setControlStyle:MPMovieControlStyleNone];
[self.view addSubview:[_player view]];
}
[_player play];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(terminateVideo)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBarHidden = YES;
}
- (void) terminateVideo
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.navigationController.navigationBarHidden = NO;
if ([_player respondsToSelector:#selector(view)])
{
[[_player view] removeFromSuperview];
}
_player = nil;
[_player release];
}
The answer to this question has an error at the end:
_player = nil;
[_player release];
These should be reversed:
[_player release];
_player = nil;
Messaging nil with release has no effect.
You can set UIStatusBarHidden in your plist, that should solve it :)

Resources