changsanjiang / SJBaseVideoPlayer

video player. rotation, volume, brightness, rate, play, pause, stop, seekToTime, present.
MIT License
128 stars 52 forks source link

Problem in Playing video in UITableView when full screen (landscape video only) #6

Open aanaipandi22 opened 4 years ago

aanaipandi22 commented 4 years ago

Dear sir, I am using the latest version 3.0.0. Problem in playing video in UITableView when the full screen button clicked only if the video orientation is landscape. If the video orientation is portrait, not a problem. Only for landscape orientation video only.

Initially I have 15 elements in the tableview array.

I also enabled the autoplay function.

Indexpath=0 , also not a problem. Playing landscape video in portrait mode at indexpath=1, then I click the full screen button then the device automatically rotate to landscape mode. Now Player not playing the first index video, immediately it call the delegate method -(void)sj_playerNeedPlayNewAssetAtIndexPath:(NSIndexPath). Now the new indexpath is 11, player playing the 11 index video. But I want to play first index video only.

After clicking the full screen button, the tableview visible index path array has the value of index path 11,12. But currently I am in index path 1 only.

I tested in XCode 11.0, Simulator iPhone 8 (iOS 13)

What is the problem?

changsanjiang commented 4 years ago

Hi @aanaipandi22. has the table view controller rotated?

Please refer to this issue for configuration rotation. https://github.com/changsanjiang/SJVideoPlayer/issues/148

aanaipandi22 commented 4 years ago

Hi, After I added the UIViewController+RotationControl.h & UIViewController+RotationControl.m files in my project, video playing properly. Now, no problem for landscape video. But previous my app support all orientation. After added this file, my app support portrait orientation only.

changsanjiang commented 4 years ago

Hi @aanaipandi22 , try these codes below:

@implementation AppDelegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAll;
}
@end

@implementation YourTableViewController
- (BOOL)shouldAutorotate {
    return NO;
}
@end

@implementation UITabBarController (RotationControl)
- (UIViewController *)sj_topViewController {
    if ( self.selectedIndex == NSNotFound )
        return self.viewControllers.firstObject;
    return self.selectedViewController;
}

- (BOOL)shouldAutorotate {
    return [[self sj_topViewController] shouldAutorotate];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return [[self sj_topViewController] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [[self sj_topViewController] preferredInterfaceOrientationForPresentation];
}
@end

@implementation UINavigationController (RotationControl)
- (BOOL)shouldAutorotate {
    return self.topViewController.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return self.topViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}

- (nullable UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}

- (nullable UIViewController *)childViewControllerForStatusBarHidden {
    return self.topViewController;
}
@end