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];
}
Related
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
I'm having trouble trying to pop a view
App Delegate
#implementation MAAppDelegate
#synthesize navController;
#synthesize detailViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Init the navController for the Master Detail View of the grade cells
UINavigationController *navController = [[UINavigationController alloc] init];
detailViewController = [[UIViewController alloc] init]; //step6
navController = [[UINavigationController alloc] initWithRootViewController:[[MAController alloc] init]]; //step7
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = navController; //step8
[self.window makeKeyAndVisible];
// Set MAController as rootViewController
//self.window.rootViewController = [[MAController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Use the insanely cool TSMessages to show network alerts
[TSMessage setDefaultViewController: self.window.rootViewController];
return YES;
}
First part of viewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:YES];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:#"Home" style:UIBarButtonItemStyleBordered target:self action:#selector(home:)];
self.navigationItem.leftBarButtonItem=newBackButton;
Later, when I change the viewController
NSLog(#"Opened progress report");
UIViewController *detailViewControl = [[UIViewController alloc] init];
// Set progress report as the view controller
[self.navigationController pushViewController:detailViewControl animated:YES];
UIImage *background = [UIImage imageNamed:#"bg"];
// Add static image bg
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backgroundImageView];
// Add blurred layer to image when tableView goes in front of it
self.blurredImageView = [[UIImageView alloc] init];
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredImageView.alpha = 0;
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.view addSubview:self.blurredImageView];
[self.navigationController setNavigationBarHidden:NO];
So I don't understand why that when I do this, a selector from the button (that I know fires, because I get Righthtere in my log):
-(void)home:(UIBarButtonItem *)sender {
NSLog(#"Righthtere");
// Set progress report as the view controller
[self.navigationController popToViewController:self animated:YES];
}
It doesn't go back to the initial view controller.
You seem to be confusing popToViewController and popViewControllerAnimated. popViewControllerAnimated removes the current view from the stack and brings the new stack top the active view controller. popToViewController pops the stack until the listed view controller is on top of the stack.
Since you are calling popToViewController with self, it will look and see that the requested view controller is already on top of the stack and do nothing. If you wish to go back one view controller then your call should be.
[self.navigationController popViewControllerAnimated:YES];
I use the below code to pop the previous viewcontroller in iOS 8.
[self presentModalViewController:viewcontroller animated:YES];
this one is driving me crazy.
From my root view controller I'm pushing another view controller to force the user to enter some credentials in order to login. Unless the credentials aren't correct the user shall not be able to switch back to the root view. To accomplish this I'm trying to hide the back button but for some reason this doesn't work.
Any suggestions?
- (void)presentLoginWebView
{
UIViewController *webViewController = [[UIViewController alloc] init];
webViewController.title = NSLocalizedString(#"IB_LOG_IN_TITLE", nil);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webViewController.view.frame];
webViewController.view = webView;
[self.navigationController pushViewController:webViewController animated:NO];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:IB_GET_OAUTH_TOKEN_URL]]];
webView.scalesPageToFit = YES;
webView.delegate = self; //delegate methods below
if (deviceVersion > 6)
{
[self.navigationController.interactivePopGestureRecognizer setEnabled:NO];
}
[self.navigationController.navigationItem setHidesBackButton:YES];
//The following line doesn't work either
//self.presentedViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];
}
The following code will work. Try only navigationItem , not navigationController.navigationItem
webViewController.navigationItem.hidesBackButton = YES;
Try hiding back button of webViewController
webViewController.navigationItem.hidesBackButton = YES;
I get an orientation problem while using the following to code to display a view on top of a split view.
[window addSubview:aSplitViewController.view];
[window insertSubview:aViewController.view aboveSubview:aSplitViewController.view];
the plain view has a couple of buttons and labels.
So the problem I am facing is that the first view opens in landscape mode but the labels and buttons on the view are in portrait mode.
UPDATE: Here is some code so if anyone wants to see more details...
In my App Delegate
- (void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
// First tabbbar item
// detail view
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *navDetailView = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
navDetailView.hidesBottomBarWhenPushed = YES;
// root view
rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.detailViewController = detailViewController;
rootViewController.navigationItem.title = #"List";
UINavigationController *navRootView = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
navRootView.hidesBottomBarWhenPushed = YES;
navRootView.navigationBar.barStyle = UIBarStyleBlackTranslucent;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem.title = #"Face Sheet";
splitViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
splitViewController.navigationItem.title = #"Face Sheet";
splitViewController.viewControllers = [NSArray arrayWithObjects:navRootView, navDetailView, nil];
splitViewController.delegate = detailViewController;
splitViewController.hidesBottomBarWhenPushed = YES;
[controllers addObject:splitViewController];
// Second tabbbar item
scoreViewController = [[ScoreCardViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
scoreViewController.tabBarItem.title = #"Score Card";
scoreViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
scoreViewController.navigationItem.title = #"Score Card";
[controllers addObject:scoreViewController];
tabBarController.viewControllers = controllers;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Create tabbar
tabBarController = [[UITabBarController alloc] init];
//tabBarController.delegate = self;
// Set window
[window addSubview:splashController.view];
[window insertSubview:tabBarController.view belowSubview:splashController.view];
[self.window makeKeyAndVisible];
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
return YES;
}
and here is the code in my SplashScreenView
- (IBAction) proceedButtonClick:(id)sender
{
// Initialize loginpopview
PhysicianLoginViewController *loginViewController = [[PhysicianLoginViewController alloc] init];
popOverController = [[UIPopoverController alloc] initWithContentViewController:loginViewController];
popOverController.popoverContentSize = CGSizeMake(350, 200);
popOverController.delegate = self;
// Set a notification to dismiss it later
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(loginViewControllerDone:) name:#"loginViewControllerDone" object:popOverController.contentViewController];
// Present popover
if ([popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
else
{
[popOverController presentPopoverFromRect:CGRectMake(485, 600, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
// Dismiss popview controller and setup the tabbar
- (void)loginViewControllerDone:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Button in content view controller was tapped, dismiss popover...
[self.popOverController dismissPopoverAnimated:YES];
// remove subview
[self.view removeFromSuperview];
// set tabbar
i3EAppDelegate *appDelegate = (i3EAppDelegate *) [[UIApplication sharedApplication]delegate];
[appDelegate makeSplitViewController];
}
It would be great if someone could point out where I am going wrong. I have been stuck with this problem for quite a few days and I have tried everything that comes to my mind...
UIWindow has a subview that it uses for rotations and puts other views inside of that. You need to insert yourself into the root view (or something lower), not the window. Look at -[UIWindow rootViewController].
UIView *rootView = [[[self window] rootViewController] view];
[rootView addSubview:view];
This will work as long as you're using something with a root view controller. This will work as long as rootViewController isn't nil. If you're doing a raw "View Based" application, then it's usually best to pick another view and add your view as its sibling rather than digging through the undocumented hierarchy:
UIView *sibling = ... (some other view)
[[sibling superview] addSubview:view];
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 :)