5

I have an iOS app with a single player and login. It should work like this:

  • 1) Run app
  • 2) login
  • 3) after login video directly starts playing
  • 4) if you exit the video it should ask for whether you want to logout
  • 5) if no should continue to playing the stream
  • 6) if yes logout the app
  • 7) and if user logs in again without killing app it should repeat the steps from 2-7

However, my code does everything except the last step. If user logs out and logs in - it starts playing the stream but when you click the done button and try to exit from video, it does not work. Video stays full screen and it gives the following warning:

Warning: <AVPlayerViewController: 0x7f9fca08aa00> is trying to exit full screen, but is not in its view's window's view controller hierarchy. This results in undefined behavior. 

I am really new to xcode ios and objectiveC and my code is as follows

- (void)viewDidLoad {

    NSLog(@"ChannelListingViewController::viewDidLoad(): Called...");
    [super viewDidLoad];

    self.check=1;

    NSLog(@"ChannelListingViewController::viewDidLoad(): Exiting...");
}

-(void) playVideo
{
    self.channelURL = [TulixAppGlobalConfig getUserSubscribedPlanChannels];


    NSURL *url = [[NSURL alloc] initWithString:[self.channelURL[1] getChannelHlsStreamURL]];
    self.player = [AVPlayer playerWithURL:url];

    // create a player view controller
    [self presentViewController:controller animated:YES completion:nil];
    self.controller.player = self.player;
    [self.player play];

}
-(void) viewDidAppear:(BOOL)animated
{

    self.controller = [[AVPlayerViewController alloc] init];

    NSLog(@"ChannelListingViewController::viewDidAppear(): Called...");
    if(self.check==0)
    {
        NSLog(@" 0 checkvalue: %i",check);
        [self showLogoutConfirmationDialog];
    }
    else{
        self.check =0;
        NSLog(@" 1 checkvalue: %i",check);
        [self playVideo];

    }

    [self spawnKeepAliveThread];
    NSLog(@"ChannelListingViewController::viewDidAppear(): Exiting...");
}

-(void) showLogoutConfirmationDialog
{
    void (^ptrFuncCompletionBlock)(void) = ^(void) {     NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog():GENERIC CALL BACK...");
    [self attemptToLogoutUser];
};
NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog(): Called...");

UIAlertAction* alertActionYes = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                             //Do Some action here
                                                             NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog:: Called for YES...");
                                                             self.check = 1;
                                                             NSLog(@" yes checkvalue: %i",check);
                                                             [self.activeAlterController dismissViewControllerAnimated:NO completion:ptrFuncCompletionBlock];
                                                             [self attemptToLogoutUser];
                                                         }];
UIAlertAction* alertActionNo = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel
                                                          handler:^(UIAlertAction * action) {
                                                              NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog:: Called for NO...");
                                                              [self playVideo];

                                                          }];

NSMutableArray* arrayAlertActions = [NSMutableArray arrayWithObjects:alertActionYes, alertActionNo, nil];
self.activeAlterController = [HelperUtility showMultiButtonDialogHavingTitle:@"Logout" withMessage:@"Are you sure you want to log out?" andAlertActions:arrayAlertActions];

[self presentViewController:self.activeAlterController animated:YES completion:nil];

NSLog(@"ChannelListingViewController::showLogoutConfirmationDialog(): Exit ");

}

I really don't understand why it does not work after the logout and need help.

C.Aglar
  • 1,290
  • 2
  • 14
  • 30
  • The thing is all the other buttons on the player are working. And when I click the done (exit) button it pauses the stream and gives the warning above. – C.Aglar Jan 16 '19 at 19:23
  • a friendly reminder: your app probably won't pass review if are willing to submit it to the app store because of limited features. – Mosbah Jan 16 '19 at 20:27
  • @Mosbah what do you mean by limited features? – C.Aglar Jan 16 '19 at 21:04
  • The error usually indicates that you are presenting fullscreen controller in the view hierarchy that does not have access to "fullscreen". Basic scenario is when presenting within controller pushed inside navigation controller. It is the navigation controller that would need to present to full screen. You have very likely similar scenario. Presenting from wrong place. – Peter Pajchl Jan 22 '19 at 18:21

1 Answers1

0

You just need to relate your avplayer controller to window view. Instead just presenting the avcontroller add below line-

Objective C-

[self.view.window.rootViewController presentViewController:controller animated:YES completion:nil];

Swift 5 -

view.window.rootViewController?.present(controller, animated: true)

Suresh Rewar
  • 117
  • 1
  • 1
  • 6
  • 1
    Hello I had this same problem and I tried the line above but I'm still getting the same issue. I have a navigation controller and multiple screens in my app. I have a button in one of the view controllers in my navigation hierarchy that plays a video in full screen, but when I exit full screen it sends me all the way back to the first view of the navigation controller, any help? Also, the view that the video plays from is a scroll view I'm not sure if that makes a difference. – shant_01 Aug 09 '20 at 04:51
  • @shant_01 I'm facing the same issue. Do you find any solution? – user12208004 Oct 17 '20 at 09:12
  • same problem. Pops back one view controller in navigation stack. – zumzum Mar 18 '21 at 04:04