Merge branch 'feature/PSDK-1173/end' into 'develop'

PSDK-1173 - Завершение видео

See merge request mobile/Flutter/nut_player!104
This commit is contained in:
Андрей Геращенко
2023-12-27 12:00:41 +03:00
8 changed files with 40 additions and 6 deletions
@@ -40,7 +40,7 @@ class PlayerViewBloc extends Bloc<PlayerViewEvent, PlayerViewState> {
on<DismissEvent>(_onDismissEvent);
on<PlayEvent>(_onPlayEvent);
on<PauseEvent>(_onPauseEvent);
on<StopEvent>(_onStopEvent);
on<EndEvent>(_onEndEvent);
on<SeekEvent>(_onSeekEvent);
on<SpeedChangedEvent>(_onSpeedChangedEvent);
on<VolumeChangedEvent>(_onVolumeChangedEvent);
@@ -107,8 +107,8 @@ class PlayerViewBloc extends Bloc<PlayerViewEvent, PlayerViewState> {
controller.pause();
}
_onStopEvent(StopEvent event, Emitter<PlayerViewState> emit) {
controller.dispose();
_onEndEvent(EndEvent event, Emitter<PlayerViewState> emit) {
controller.end();
}
_onSeekEvent(SeekEvent event, Emitter<PlayerViewState> emit) async {
@@ -17,8 +17,8 @@ class PauseEvent extends PlayerViewEvent {
const PauseEvent();
}
class StopEvent extends PlayerViewEvent {
const StopEvent();
class EndEvent extends PlayerViewEvent {
const EndEvent();
}
class SeekEvent extends PlayerViewEvent {
@@ -171,7 +171,7 @@ class _PlayerViewState extends State<PlayerView> {
}),
const SizedBox(width: 10),
PlayerButton('Завершить', () {
_bloc.add(const StopEvent());
_bloc.add(const EndEvent());
})
],
),
@@ -240,6 +240,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _applyPlayPause();
}
/// Завершение видео.
Future<void> end() async {
final playerId = _playerId;
if (_isDisposedOrNotInitialized || playerId == null) {
return;
}
await nutPlayerPlatform.end(playerId);
}
/// Seek video.
Future<void> seek(Duration position) async {
final playerId = _playerId;
@@ -70,6 +70,8 @@ public class NutPlayerIosPlugin: NSObject, FlutterPlugin, NutPlayerViewFactoryDe
self.pluginPlay(arguments, result: result)
case "pluginPause":
self.pluginPause(arguments, result: result)
case "pluginEnd":
self.pluginEnd(arguments, result: result)
case "pluginSetVolume":
self.pluginSetVolume(arguments, result: result)
case "pluginGetVolume":
@@ -172,6 +174,17 @@ public class NutPlayerIosPlugin: NSObject, FlutterPlugin, NutPlayerViewFactoryDe
result(nil)
}
private func pluginEnd(_ arguments: [Any], result: @escaping FlutterResult) {
guard let playerId = arguments.first as? Int64,
let record = self.players[playerId] else {
result(FlutterMethodNotImplemented)
return
}
record.platform.end()
result(nil)
}
private func pluginPause(_ arguments: [Any], result: @escaping FlutterResult) {
guard let playerId = arguments.first as? Int64,
let record = self.players[playerId] else {
@@ -259,6 +259,8 @@ final class PlayerFlutterPlatform: NSObject, FlutterStreamHandler {
func play() { self.nutPlayer?.play() }
func end() { self.nutPlayer?.end() }
func pause() {
guard let player = self.nutPlayer,
player.state.value != .completed else {
@@ -132,6 +132,11 @@ class NutPlayerIosPlatform extends NutPlayerPlatform {
return _pluginChannel.invokeMethod("pluginPause", [playerId]);
}
@override
Future<void> end(PlayerId playerID) {
return _pluginChannel.invokeMethod("pluginEnd", [playerID]);
}
@override
Future<int> state(PlayerId playerId) async {
final result = await _pluginChannel.invokeMethod("pluginGetState", [playerId]);
@@ -67,6 +67,11 @@ abstract class NutPlayerPlatform extends PlatformInterface {
throw UnimplementedError('pause() has not been implemented.');
}
/// Завершает видео.
Future<void> end(PlayerId playerId) {
throw UnimplementedError('end() has not been implemented.');
}
Future<double> volume(PlayerId playerId) async {
throw UnimplementedError('volume() has not been implemented.');
}