Commit f0192bec authored by Carola Nitz's avatar Carola Nitz

VLCDisplayController, VLCMiniPlaybackView: first playback fixes

Created a subclass for the  view of the VLCDisplayController to let touches go through
Have only one instance of the Playbackcontroller that is going to be part of the tabbarcontroller
Changed the code that is currently calculating the miniviews position. This still needs fixing in case you turn the phone
parent fe372899
......@@ -386,11 +386,10 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
return;
}
}
__weak typeof(self) weakself = self;
[self validatePasscodeIfNeededWithCompletion:^{
//[weakself.libraryViewController updateViewContents];
//TODO: handle updating the videoview and
if ([VLCPlaybackController sharedInstance].isPlaying){
[[VLCPlayerDisplayController sharedInstance] pushPlaybackView];
//TODO: push playback
}
}];
[[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
......@@ -401,6 +400,7 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
if (!_isRunningMigration && !_isComingFromHandoff) {
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
// [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
[[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
} else if(_isComingFromHandoff) {
_isComingFromHandoff = NO;
}
......@@ -453,7 +453,7 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
- (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
{
if ([VLCKeychainCoordinator passcodeLockEnabled]) {
[[VLCPlayerDisplayController sharedInstance] dismissPlaybackView];
//TODO: Dimiss playback
[self.keychainCoordinator validatePasscodeWithCompletion:completion];
} else {
completion();
......
......@@ -456,7 +456,7 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
_createFolderBarButtonItem.enabled = NO;
[_mediaDataSource addAllShows];
} break;
//Todo: I'm not sure if updateViewContents should be called in VLCLibraryModeFolder
//TODO: I'm not sure if updateViewContents should be called in VLCLibraryModeFolder
//Here should maybe be an NSAssert to prevent this but for now due to refactoring these calls would've been made in that case
case VLCLibraryModeAllFiles:
case VLCLibraryModeFolder:
......
......@@ -6,13 +6,12 @@
* $Id$
*
* Author: Felix Paul Kühne <fkuehne # videolan.org>
* Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCMiniPlaybackView.h"
#import "VLCPlaybackController.h"
#import "VLCPlayerDisplayController.h"
#import "VLCMetadata.h"
#import "VLC_iOS-Swift.h"
......@@ -38,12 +37,6 @@
self = [super initWithFrame:viewFrame];
if (self) {
[self setupSubviews];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(appBecameActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
return self;
}
......@@ -146,14 +139,6 @@
#endif
}
- (void)appBecameActive:(NSNotification *)aNotification
{
VLCPlayerDisplayController *pdc = [VLCPlayerDisplayController sharedInstance];
if (pdc.displayMode == VLCPlayerDisplayControllerDisplayModeMiniplayer) {
[[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
}
}
- (void)tapRecognized
{
[self pushFullPlaybackView:nil];
......@@ -209,6 +194,8 @@
[self updatePlayPauseButton];
controller.delegate = self;
[controller recoverDisplayedMetadata];
_videoView.hidden = false;
controller.videoOutputView = _videoView;
}
- (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState
......@@ -228,11 +215,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
_artworkView.image = metadata.artworkImage?: [UIImage imageNamed:@"no-artwork"];
} else {
_artworkView.image = nil;
VLCPlayerDisplayController *pdc = [VLCPlayerDisplayController sharedInstance];
if (pdc.displayMode == VLCPlayerDisplayControllerDisplayModeMiniplayer) {
_videoView.hidden = false;
controller.videoOutputView = _videoView;
}
}
NSString *metaDataString;
......
......@@ -17,10 +17,10 @@
@class OBSlider;
@class VLCStatusLabel;
@class VLCHorizontalSwipeGestureRecognizer;
@class VLCVerticalSwipeGestureRecognizer;
@class VLCTimeNavigationTitleView;
@class VLCMovieViewControlPanelView;
@class VLCMovieViewController;
typedef NS_ENUM(NSInteger, VLCMovieJumpState) {
VLCMovieJumpStateDefault,
......@@ -28,6 +28,11 @@ typedef NS_ENUM(NSInteger, VLCMovieJumpState) {
VLCMovieJumpStateBackward
};
@protocol VLCMovieViewControllerDelegate
- (void)movieViewControllerDidSelectMinimize:(VLCMovieViewController *)movieViewController;
- (BOOL)movieViewControllerShouldBeDisplayed:(VLCMovieViewController *)movieViewController;
@end
@interface VLCMovieViewController : UIViewController <UIActionSheetDelegate, VLCPlaybackControllerDelegate>
@property (nonatomic, strong) IBOutlet UIView *movieView;
......@@ -73,6 +78,8 @@ typedef NS_ENUM(NSInteger, VLCMovieJumpState) {
@property (nonatomic, strong) IBOutlet UIImageView *artworkImageView;
@property (nonatomic, strong) IBOutlet NSLayoutConstraint *widthConstraint;
@property (nonatomic, weak) id<VLCMovieViewControllerDelegate> delegate;
- (IBAction)closePlayback:(id)sender;
- (IBAction)minimizePlayback:(id)sender;
......
......@@ -27,7 +27,6 @@
#import "VLCPlaybackController.h"
#import "UIDevice+VLC.h"
#import "VLCTimeNavigationTitleView.h"
#import "VLCPlayerDisplayController.h"
#import "VLCAppDelegate.h"
#import "VLCStatusLabel.h"
#import "VLCMovieViewControlPanelView.h"
......@@ -832,7 +831,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
- (IBAction)minimizePlayback:(id)sender
{
LOCKCHECK;
[[VLCPlayerDisplayController sharedInstance] closeFullscreenPlayback];
[_delegate movieViewControllerDidSelectMinimize:self];
}
- (IBAction)positionSliderAction:(UISlider *)sender
......@@ -1512,8 +1511,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
- (void)appBecameActive:(NSNotification *)aNotification
{
VLCPlayerDisplayController *pdc = [VLCPlayerDisplayController sharedInstance];
if (pdc.displayMode == VLCPlayerDisplayControllerDisplayModeFullscreen) {
if ([_delegate movieViewControllerShouldBeDisplayed:self]) {
[_vpc recoverDisplayedMetadata];
if (_vpc.videoOutputView != self.movieView) {
_vpc.videoOutputView = self.movieView;
......
......@@ -12,7 +12,9 @@
*****************************************************************************/
#import "VLCEqualizerView.h"
#if TARGET_OS_iOS
#import <MobileVLCKit/MobileVLCKit.h>
#endif
extern NSString *const VLCPlaybackControllerPlaybackDidStart;
extern NSString *const VLCPlaybackControllerPlaybackDidPause;
extern NSString *const VLCPlaybackControllerPlaybackDidResume;
......
......@@ -30,8 +30,6 @@ typedef NS_ENUM(NSUInteger, VLCPlayerDisplayControllerDisplayMode) {
@interface VLCPlayerDisplayController : UIViewController
+ (VLCPlayerDisplayController *)sharedInstance;
@property (nonatomic, assign) VLCPlayerDisplayControllerDisplayMode displayMode;
@property (nonatomic, weak) VLCPlaybackController *playbackController;
......
......@@ -24,30 +24,26 @@
static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDisplayControllerDisplayMode";
@interface VLCPlayerDisplayController ()
@property (nonatomic, strong) UIViewController<VLCPlaybackControllerDelegate> *movieViewController;
@property (nonatomic, strong) UIView<VLCPlaybackControllerDelegate, VLCMiniPlaybackViewInterface> *miniPlaybackView;
@property (nonatomic, strong) UIViewController *childViewController;
@interface VLCUntouchableView: UIView
@end
@implementation VLCPlayerDisplayController
@implementation VLCUntouchableView
+ (VLCPlayerDisplayController *)sharedInstance
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
static VLCPlayerDisplayController *sharedInstance = nil;
static dispatch_once_t pred;
UIView *result = [super hitTest:point withEvent:event];
return result == self ? nil : result;
}
dispatch_once(&pred, ^{
sharedInstance = [VLCPlayerDisplayController new];
});
@end
return sharedInstance;
}
@interface VLCPlayerDisplayController () <VLCMovieViewControllerDelegate>
@property (nonatomic, strong) UIViewController<VLCPlaybackControllerDelegate> *movieViewController;
@property (nonatomic, strong) UIView<VLCPlaybackControllerDelegate, VLCMiniPlaybackViewInterface> *miniPlaybackView;
@property (nonatomic, strong) NSLayoutConstraint *bottomConstraint;
@end
+ (void)initialize
{
[[NSUserDefaults standardUserDefaults] registerDefaults:@{VLCPlayerDisplayControllerDisplayModeKey : @(VLCPlayerDisplayControllerDisplayModeFullscreen)}];
}
@implementation VLCPlayerDisplayController
- (instancetype)init
{
......@@ -57,39 +53,14 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
[notificationCenter addObserver:self selector:@selector(playbackDidStart:) name:VLCPlaybackControllerPlaybackDidStart object:nil];
[notificationCenter addObserver:self selector:@selector(playbackDidFail:) name:VLCPlaybackControllerPlaybackDidFail object:nil];
[notificationCenter addObserver:self selector:@selector(playbackDidStop:) name:VLCPlaybackControllerPlaybackDidStop object:nil];
self.view.userInteractionEnabled = NO;
[[NSUserDefaults standardUserDefaults] registerDefaults:@{VLCPlayerDisplayControllerDisplayModeKey : @(VLCPlayerDisplayControllerDisplayModeFullscreen)}];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - ChildViewController
- (void)setChildViewController:(UIViewController *)childViewController
{
if (_childViewController) {
[_childViewController willMoveToParentViewController:nil];
[_childViewController.view removeFromSuperview];
[_childViewController removeFromParentViewController];
}
_childViewController = childViewController;
if (self.isViewLoaded) {
[self setupChildViewController];
}
}
- (void)setupChildViewController
- (void)viewDidLoad
{
UIViewController *childViewController = self.childViewController;
if (childViewController == nil)
return;
[self addChildViewController:childViewController];
[self.view addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];
self.view = [[VLCUntouchableView alloc] initWithFrame:self.view.frame];
}
#pragma mark - properties
......@@ -104,16 +75,6 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
[[NSUserDefaults standardUserDefaults] setInteger:displayMode forKey:VLCPlayerDisplayControllerDisplayModeKey];
}
- (void)viewSafeAreaInsetsDidChange
{
if (@available(iOS 11.0, *)) {
[super viewSafeAreaInsetsDidChange];
CGRect frame = _miniPlaybackView.frame;
frame.size.height = 60.0 + self.view.safeAreaInsets.bottom;
_miniPlaybackView.frame = frame;
}
}
- (VLCPlaybackController *)playbackController {
if (_playbackController == nil) {
_playbackController = [VLCPlaybackController sharedInstance];
......@@ -126,6 +87,7 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
if (!_movieViewController) {
#if TARGET_OS_IOS
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
((VLCMovieViewController *)_movieViewController).delegate = self;
#else
_movieViewController = [[VLCFullscreenMovieTVViewController alloc] initWithNibName:nil bundle:nil];
#endif
......@@ -178,7 +140,7 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
- (void)closeFullscreenPlayback
{
[self _closeFullscreenPlayback];
[self.movieViewController dismissViewControllerAnimated:[self shouldAnimate] completion:nil];
self.displayMode = VLCPlayerDisplayControllerDisplayModeMiniplayer;
[self _showHideMiniPlaybackView];
}
......@@ -298,15 +260,6 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
const BOOL activePlaybackSession = playbackController.isPlaying || playbackController.willPlay;
const BOOL miniPlayerVisible = miniPlaybackView.visible;
const CGRect viewRect = self.view.bounds;
CGFloat miniPlayerHeight = 60.;
if (@available(iOS 11.0, *)) {
miniPlayerHeight += self.view.safeAreaInsets.bottom;
}
const CGRect miniPlayerFrameIn = CGRectMake(0., viewRect.size.height-miniPlayerHeight-self.view.layoutMargins.bottom, viewRect.size.width, miniPlayerHeight);
const CGRect miniPlayerFrameOut = CGRectMake(0., viewRect.size.height, viewRect.size.width, miniPlayerHeight);
BOOL needsShow = activePlaybackSession && !miniPlayerVisible;
BOOL needsHide = !activePlaybackSession && miniPlayerVisible;
......@@ -318,9 +271,18 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
void (^completionBlock)(BOOL) = nil;
if (needsShow) {
if (!miniPlaybackView) {
self.miniPlaybackView = miniPlaybackView = [[VLCMiniPlaybackView alloc] initWithFrame:miniPlayerFrameOut];
miniPlaybackView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
self.miniPlaybackView = miniPlaybackView = [[VLCMiniPlaybackView alloc] initWithFrame:CGRectZero];
miniPlaybackView.translatesAutoresizingMaskIntoConstraints = NO;
miniPlaybackView.userInteractionEnabled = YES;
[self.view addSubview:miniPlaybackView];
_bottomConstraint = [miniPlaybackView.topAnchor constraintEqualToAnchor:self.view.bottomAnchor];
[NSLayoutConstraint activateConstraints:
@[_bottomConstraint,
[miniPlaybackView.heightAnchor constraintEqualToConstant:60.0],
[miniPlaybackView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
[miniPlaybackView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
]];
[self.view layoutIfNeeded];
}
miniPlaybackView.visible = YES;
} else if (needsHide) {
......@@ -341,22 +303,27 @@ static NSString *const VLCPlayerDisplayControllerDisplayModeKey = @"VLCPlayerDis
[miniPlaybackView prepareForMediaPlayback:playbackController];
if (needsShow || needsHide) {
UIViewController *childViewController = self.childViewController;
const CGRect newMiniPlayerFrame = needsHide ? miniPlayerFrameOut : miniPlayerFrameIn;
CGRect newChildViewFrame = childViewController.view.frame;
newChildViewFrame.size.height = CGRectGetMinY(newMiniPlayerFrame)-CGRectGetMinY(newChildViewFrame);
[UIView animateWithDuration:animationDuration
delay:animationDuration
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction
animations:^{
miniPlaybackView.frame = newMiniPlayerFrame;
childViewController.view.frame = newChildViewFrame;
self.bottomConstraint.constant = needsHide ? 0 : -_miniPlaybackView.frame.size.height -self.view.layoutMargins.bottom;
[self.view layoutIfNeeded];
}
completion:completionBlock];
}
#endif
}
#pragma mark - MovieViewControllerDelegate
- (void)movieViewControllerDidSelectMinimize:(VLCMovieViewController *)movieViewController
{
[self closeFullscreenPlayback];
}
- (BOOL)movieViewControllerShouldBeDisplayed:(VLCMovieViewController *)movieViewController
{
return self.displayMode == VLCPlayerDisplayControllerDisplayModeFullscreen;
}
@end
......@@ -51,6 +51,12 @@ class VLCTabbarCooordinator: NSObject, VLCMediaViewControllerDelegate, UITabBarC
}
func setupViewControllers() {
tabBarController.addChildViewController(displayController)
tabBarController.view.addSubview(displayController.view)
displayController.view.layoutMargins = UIEdgeInsets(top:0, left:0, bottom:tabBarController.tabBar.frame.size.height, right:0)
displayController.didMove(toParentViewController: tabBarController)
let videoVC = VLCMediaViewController(services: services)
//this should probably not be the delegate
videoVC.delegate = self
......@@ -142,18 +148,12 @@ class VLCTabbarCooordinator: NSObject, VLCMediaViewControllerDelegate, UITabBarC
func playMedia(media: NSManagedObject) {
//that should go into a Coordinator itself
let displayController = VLCPlayerDisplayController()
tabBarController.addChildViewController(displayController)
tabBarController.view.addSubview(displayController.view)
displayController.view.layoutMargins = UIEdgeInsets(top:0, left:0, bottom:tabBarController.tabBar.frame.size.height, right:0)
displayController.didMove(toParentViewController: tabBarController)
displayController.displayMode = .miniplayer
let vpc = VLCPlaybackController.sharedInstance()
vpc?.playMediaLibraryObject(media)
}
func showSortOptions() {
//should probably be in a coordinator as well
//This should be in a subclass
let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("Sort by",comment: ""), message: nil, preferredStyle: .actionSheet)
let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.string, style: .default) { action in
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment