diff --git a/example/lib/pages/notification_player_page.dart b/example/lib/pages/notification_player_page.dart index e5cd3365a..de01da995 100644 --- a/example/lib/pages/notification_player_page.dart +++ b/example/lib/pages/notification_player_page.dart @@ -33,6 +33,8 @@ class _NotificationPlayerPageState extends State { title: "Elephant dream", author: "Some author", imageUrl: Constants.catImageUrl, + skipForwardTimeInMilliseconds: 15000, + skipBackwardTimeInMilliseconds: 15000, ), ); _betterPlayerController.setupDataSource(dataSource); diff --git a/ios/Classes/BetterPlayerPlugin.m b/ios/Classes/BetterPlayerPlugin.m index ed50403fa..6241fc47e 100644 --- a/ios/Classes/BetterPlayerPlugin.m +++ b/ios/Classes/BetterPlayerPlugin.m @@ -97,10 +97,12 @@ - (void) setupRemoteNotification :(BetterPlayer*) player{ NSString* title = dataSource[@"title"]; NSString* author = dataSource[@"author"]; NSString* imageUrl = dataSource[@"imageUrl"]; + int64_t skipForwardTimeInMilliseconds = [dataSource[@"skipForwardTimeInMilliseconds"] intValue]; + int64_t skipBackwardTimeInMilliseconds = [dataSource[@"skipBackwardTimeInMilliseconds"] intValue]; if (showNotification){ [self setRemoteCommandsNotificationActive]; - [self setupRemoteCommands: player]; + [self setupRemoteCommands: player, skipForwardTimeInMilliseconds, skipBackwardTimeInMilliseconds]; [self setupRemoteCommandNotification: player, title, author, imageUrl]; [self setupUpdateListener: player, title, author, imageUrl]; } @@ -120,7 +122,7 @@ - (void) setRemoteCommandsNotificationNotActive{ } -- (void) setupRemoteCommands:(BetterPlayer*)player { +- (void) setupRemoteCommands:(BetterPlayer*)player, skipForwardTimeInMilliseconds, skipBackwardTimeInMilliseconds { if (_remoteCommandsInitialized){ return; } @@ -128,12 +130,15 @@ - (void) setupRemoteCommands:(BetterPlayer*)player { [commandCenter.togglePlayPauseCommand setEnabled:YES]; [commandCenter.playCommand setEnabled:YES]; [commandCenter.pauseCommand setEnabled:YES]; - [commandCenter.nextTrackCommand setEnabled:NO]; - [commandCenter.previousTrackCommand setEnabled:NO]; + [commandCenter.skipForwardCommand setEnabled:YES]; + [commandCenter.skipBackwardCommand setEnabled:YES]; if (@available(iOS 9.1, *)) { [commandCenter.changePlaybackPositionCommand setEnabled:YES]; } + commandCenter.skipForwardCommand.preferredIntervals = @[@(skipForwardTimeInMilliseconds/1000)]; + commandCenter.skipBackwardCommand.preferredIntervals = @[@(skipBackwardTimeInMilliseconds/1000)]; + [commandCenter.togglePlayPauseCommand addTargetWithHandler: ^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) { if (_notificationPlayer != [NSNull null]){ if (_notificationPlayer.isPlaying){ @@ -159,7 +164,21 @@ - (void) setupRemoteCommands:(BetterPlayer*)player { return MPRemoteCommandHandlerStatusSuccess; }]; + [commandCenter.skipForwardCommand addTargetWithHandler: ^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) { + if (_notificationPlayer != [NSNull null]){ + int64_t millis = [_notificationPlayer position] + skipForwardTimeInMilliseconds; + _notificationPlayer.eventSink(@{@"event" : @"seek", @"position": @(millis)}); + } + return MPRemoteCommandHandlerStatusSuccess; + }]; + [commandCenter.skipBackwardCommand addTargetWithHandler: ^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) { + if (_notificationPlayer != [NSNull null]){ + int64_t millis = [_notificationPlayer position] - skipBackwardTimeInMilliseconds; + _notificationPlayer.eventSink(@{@"event" : @"seek", @"position": @(millis)}); + } + return MPRemoteCommandHandlerStatusSuccess; + }]; if (@available(iOS 9.1, *)) { [commandCenter.changePlaybackPositionCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) { diff --git a/lib/src/configuration/better_player_notification_configuration.dart b/lib/src/configuration/better_player_notification_configuration.dart index 1c9718b74..9a6e4a047 100644 --- a/lib/src/configuration/better_player_notification_configuration.dart +++ b/lib/src/configuration/better_player_notification_configuration.dart @@ -13,6 +13,12 @@ class BetterPlayerNotificationConfiguration { ///Image of the video, used in controls notification final String? imageUrl; + ///Time for skip forward, used in controls notification + final int? skipForwardTimeInMilliseconds; + + ///Time for skip backward, used in controls notification + final int? skipBackwardTimeInMilliseconds; + ///Name of the notification channel. Used only in Android. final String? notificationChannelName; @@ -27,5 +33,7 @@ class BetterPlayerNotificationConfiguration { this.imageUrl, this.notificationChannelName, this.activityName, + this.skipForwardTimeInMilliseconds = 10000, + this.skipBackwardTimeInMilliseconds = 10000, }); } diff --git a/lib/src/core/better_player_controller.dart b/lib/src/core/better_player_controller.dart index d1a53bc31..3ac0a0563 100644 --- a/lib/src/core/better_player_controller.dart +++ b/lib/src/core/better_player_controller.dart @@ -458,6 +458,10 @@ class BetterPlayerController { author: _betterPlayerDataSource?.notificationConfiguration?.author, imageUrl: _betterPlayerDataSource?.notificationConfiguration?.imageUrl, + skipForwardTimeInMilliseconds: _betterPlayerDataSource + ?.notificationConfiguration?.skipForwardTimeInMilliseconds, + skipBackwardTimeInMilliseconds: _betterPlayerDataSource + ?.notificationConfiguration?.skipBackwardTimeInMilliseconds, notificationChannelName: _betterPlayerDataSource ?.notificationConfiguration?.notificationChannelName, overriddenDuration: _betterPlayerDataSource!.overriddenDuration, @@ -490,6 +494,10 @@ class BetterPlayerController { author: _betterPlayerDataSource?.notificationConfiguration?.author, imageUrl: _betterPlayerDataSource?.notificationConfiguration?.imageUrl, + skipForwardTimeInMilliseconds: _betterPlayerDataSource + ?.notificationConfiguration?.skipForwardTimeInMilliseconds, + skipBackwardTimeInMilliseconds: _betterPlayerDataSource + ?.notificationConfiguration?.skipBackwardTimeInMilliseconds, notificationChannelName: _betterPlayerDataSource ?.notificationConfiguration?.notificationChannelName, overriddenDuration: _betterPlayerDataSource!.overriddenDuration, @@ -510,6 +518,10 @@ class BetterPlayerController { _betterPlayerDataSource?.notificationConfiguration?.author, imageUrl: _betterPlayerDataSource?.notificationConfiguration?.imageUrl, + skipForwardTimeInMilliseconds: _betterPlayerDataSource + ?.notificationConfiguration?.skipForwardTimeInMilliseconds, + skipBackwardTimeInMilliseconds: _betterPlayerDataSource + ?.notificationConfiguration?.skipBackwardTimeInMilliseconds, notificationChannelName: _betterPlayerDataSource ?.notificationConfiguration?.notificationChannelName, overriddenDuration: _betterPlayerDataSource!.overriddenDuration, diff --git a/lib/src/video_player/method_channel_video_player.dart b/lib/src/video_player/method_channel_video_player.dart index a4066d5f0..be9e22d3a 100644 --- a/lib/src/video_player/method_channel_video_player.dart +++ b/lib/src/video_player/method_channel_video_player.dart @@ -68,6 +68,10 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform { 'title': dataSource.title, 'author': dataSource.author, 'imageUrl': dataSource.imageUrl, + 'skipForwardTimeInMilliseconds': + dataSource.skipForwardTimeInMilliseconds, + 'skipBackwardTimeInMilliseconds': + dataSource.skipBackwardTimeInMilliseconds, 'notificationChannelName': dataSource.notificationChannelName, 'overriddenDuration': dataSource.overriddenDuration?.inMilliseconds, 'activityName': dataSource.activityName @@ -87,6 +91,10 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform { 'title': dataSource.title, 'author': dataSource.author, 'imageUrl': dataSource.imageUrl, + 'skipForwardTimeInMilliseconds': + dataSource.skipForwardTimeInMilliseconds, + 'skipBackwardTimeInMilliseconds': + dataSource.skipBackwardTimeInMilliseconds, 'notificationChannelName': dataSource.notificationChannelName, 'overriddenDuration': dataSource.overriddenDuration?.inMilliseconds, 'licenseUrl': dataSource.licenseUrl, @@ -108,6 +116,10 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform { 'title': dataSource.title, 'author': dataSource.author, 'imageUrl': dataSource.imageUrl, + 'skipForwardTimeInMilliseconds': + dataSource.skipForwardTimeInMilliseconds, + 'skipBackwardTimeInMilliseconds': + dataSource.skipBackwardTimeInMilliseconds, 'notificationChannelName': dataSource.notificationChannelName, 'overriddenDuration': dataSource.overriddenDuration?.inMilliseconds, 'activityName': dataSource.activityName, diff --git a/lib/src/video_player/video_player.dart b/lib/src/video_player/video_player.dart index 7a8453f13..96910ae54 100644 --- a/lib/src/video_player/video_player.dart +++ b/lib/src/video_player/video_player.dart @@ -287,6 +287,8 @@ class VideoPlayerController extends ValueNotifier { String? title, String? author, String? imageUrl, + int? skipForwardTimeInMilliseconds, + int? skipBackwardTimeInMilliseconds, String? notificationChannelName, Duration? overriddenDuration, String? activityName, @@ -300,6 +302,8 @@ class VideoPlayerController extends ValueNotifier { title: title, author: author, imageUrl: imageUrl, + skipForwardTimeInMilliseconds: skipForwardTimeInMilliseconds, + skipBackwardTimeInMilliseconds: skipBackwardTimeInMilliseconds, notificationChannelName: notificationChannelName, overriddenDuration: overriddenDuration, activityName: activityName, @@ -327,6 +331,8 @@ class VideoPlayerController extends ValueNotifier { String? title, String? author, String? imageUrl, + int? skipForwardTimeInMilliseconds, + int? skipBackwardTimeInMilliseconds, String? notificationChannelName, Duration? overriddenDuration, String? licenseUrl, @@ -350,6 +356,8 @@ class VideoPlayerController extends ValueNotifier { title: title, author: author, imageUrl: imageUrl, + skipForwardTimeInMilliseconds: skipForwardTimeInMilliseconds, + skipBackwardTimeInMilliseconds: skipBackwardTimeInMilliseconds, notificationChannelName: notificationChannelName, overriddenDuration: overriddenDuration, licenseUrl: licenseUrl, @@ -371,6 +379,8 @@ class VideoPlayerController extends ValueNotifier { String? title, String? author, String? imageUrl, + int? skipForwardTimeInMilliseconds, + int? skipBackwardTimeInMilliseconds, String? notificationChannelName, Duration? overriddenDuration, String? activityName, @@ -383,6 +393,8 @@ class VideoPlayerController extends ValueNotifier { title: title, author: author, imageUrl: imageUrl, + skipForwardTimeInMilliseconds: skipForwardTimeInMilliseconds, + skipBackwardTimeInMilliseconds: skipBackwardTimeInMilliseconds, notificationChannelName: notificationChannelName, overriddenDuration: overriddenDuration, activityName: activityName, diff --git a/lib/src/video_player/video_player_platform_interface.dart b/lib/src/video_player/video_player_platform_interface.dart index 336f54b04..2ef4dd9e2 100644 --- a/lib/src/video_player/video_player_platform_interface.dart +++ b/lib/src/video_player/video_player_platform_interface.dart @@ -219,6 +219,8 @@ class DataSource { this.title, this.author, this.imageUrl, + this.skipForwardTimeInMilliseconds, + this.skipBackwardTimeInMilliseconds, this.notificationChannelName, this.overriddenDuration, this.licenseUrl, @@ -289,6 +291,10 @@ class DataSource { final String? imageUrl; + final int? skipForwardTimeInMilliseconds; + + final int? skipBackwardTimeInMilliseconds; + final String? notificationChannelName; final Duration? overriddenDuration; diff --git a/test/mock_video_player_controller.dart b/test/mock_video_player_controller.dart index b9bceebab..7574efd84 100644 --- a/test/mock_video_player_controller.dart +++ b/test/mock_video_player_controller.dart @@ -66,6 +66,8 @@ class MockVideoPlayerController extends VideoPlayerController { String? title, String? author, String? imageUrl, + int? skipForwardTimeInMilliseconds, + int? skipBackwardTimeInMilliseconds, String? notificationChannelName, Duration? overriddenDuration, String? licenseUrl,