Skip to content

Commit

Permalink
VLCPlayerDisplayController: Improve the player switch
Browse files Browse the repository at this point in the history
The player now switches to the proper one depending on the media
type when the playback moves on to the next media.

If the mini player is displayed, it remains even if the media type
switches.
  • Loading branch information
Diogo Simao Marques authored and fkuehne committed Oct 22, 2024
1 parent 60cb8f3 commit 2e0df52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Sources/Playback/Control/VLCPlayerDisplayController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@class VLCServices;
@class VLCQueueViewController;

typedef NS_ENUM(UInt8, VLCMLMediaType);

NS_ASSUME_NONNULL_BEGIN

extern NSString * const VLCPlayerDisplayControllerDisplayMiniPlayer;
Expand Down Expand Up @@ -56,6 +58,7 @@ typedef NS_ENUM(NSUInteger, VLCPlayerDisplayControllerDisplayMode) {
@property (nullable, nonatomic, readonly) NSArray<UIKeyCommand *> *keyCommands;
@property (nonatomic, readonly) BOOL canBecomeFirstResponder;
@property (readonly, nullable) UIViewController *videoPlayerViewController;
@property (readwrite, nonatomic) VLCMLMediaType currentMediaType;

- (nullable instancetype)init;
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil
Expand Down
28 changes: 26 additions & 2 deletions Sources/Playback/Control/VLCPlayerDisplayController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (nullable instancetype)init
[notificationCenter addObserver:self selector:@selector(playbackDidStart:) name:VLCPlaybackServicePlaybackDidStart object:nil];
[notificationCenter addObserver:self selector:@selector(playbackDidFail:) name:VLCPlaybackServicePlaybackDidFail object:nil];
[notificationCenter addObserver:self selector:@selector(playbackDidStop:) name:VLCPlaybackServicePlaybackDidStop object:nil];
[notificationCenter addObserver:self selector:@selector(playbackDidMoveToNextMedia:) name:VLCPlaybackServicePlaybackDidMoveOnToNextItem object:nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:@{VLCPlayerDisplayControllerDisplayModeKey : @(VLCPlayerDisplayControllerDisplayModeFullscreen)}];
}
return self;
Expand Down Expand Up @@ -161,11 +162,12 @@ - (void)playbackDidStart:(NSNotification *)notification
VLCMedia *currentMedia = _playbackController.currentlyPlayingMedia;
VLCMLMedia *media = [VLCMLMedia mediaForPlayingMedia:currentMedia];

_playbackController.fullscreenSessionRequested = [media type] != VLCMLMediaTypeAudio;
_currentMediaType = [media type];
_playbackController.fullscreenSessionRequested = _currentMediaType != VLCMLMediaTypeAudio;

if (self.playbackController.fullscreenSessionRequested && enforceFullscreen) {
[self setDisplayMode:VLCPlayerDisplayControllerDisplayModeFullscreen];
} else if ([media type] == VLCMLMediaTypeAudio && _playbackController.numberOfVideoTracks > 0) {
} else if (_currentMediaType == VLCMLMediaTypeAudio && _playbackController.numberOfVideoTracks > 0) {
[self setDisplayMode:VLCPlayerDisplayControllerDisplayModeFullscreen];
}

Expand Down Expand Up @@ -194,13 +196,35 @@ - (void)playbackDidStart:(NSNotification *)notification
- (void)playbackDidStop:(NSNotification *)notification
{
[self dismissPlaybackView];
_currentMediaType = VLCMLMediaTypeUnknown;
}

- (void)playbackDidFail:(NSNotification *)notification
{
[self showPlaybackError];
}

- (void)playbackDidMoveToNextMedia:(NSNotification *)notification
{
VLCMedia *currentMedia = _playbackController.currentlyPlayingMedia;
VLCMLMedia *media = [VLCMLMedia mediaForPlayingMedia:currentMedia];

VLCMLMediaType mediaType = [media type];
if (media == nil || mediaType == VLCMLMediaTypeUnknown || [self isMiniPlayerVisible]) {
return;
}

if (_currentMediaType == VLCMLMediaTypeAudio && mediaType == VLCMLMediaTypeVideo) {
[self dismissPlaybackView];
[self showFullscreenPlayback];
} else if (_currentMediaType == VLCMLMediaTypeVideo && mediaType == VLCMLMediaTypeAudio) {
[self dismissPlaybackView];
[self showAudioPlayer];
}

_currentMediaType = mediaType;
}

#pragma mark - API

- (void)showFullscreenPlayback
Expand Down

0 comments on commit 2e0df52

Please sign in to comment.