mucke/lib/system/models/playback_event_model.dart

46 lines
1.4 KiB
Dart
Raw Normal View History

2020-12-13 12:37:08 +01:00
import 'package:just_audio/just_audio.dart' as ja;
2020-12-20 16:21:48 +01:00
import '../../domain/entities/playback_event.dart';
2020-12-13 12:37:08 +01:00
2020-12-20 16:21:48 +01:00
class PlaybackEventModel extends PlaybackEvent {
PlaybackEventModel({
2021-06-20 13:49:21 +02:00
required int index,
required bool playing,
required ProcessingState processingState,
required Duration updatePosition,
required DateTime updateTime,
2020-12-20 16:21:48 +01:00
}) : super(
index: index,
playing: playing,
2020-12-20 16:21:48 +01:00
processingState: processingState,
updatePosition: updatePosition,
updateTime: updateTime,
);
2020-12-13 12:37:08 +01:00
factory PlaybackEventModel.fromJAPlaybackEvent(ja.PlaybackEvent playbackEvent, bool playing) =>
2020-12-20 16:21:48 +01:00
PlaybackEventModel(
2021-06-20 13:49:21 +02:00
index: playbackEvent.currentIndex ?? -1,
playing: playing,
2020-12-20 16:21:48 +01:00
processingState: playbackEvent.processingState.toProcessingState(),
updatePosition: playbackEvent.updatePosition,
updateTime: playbackEvent.updateTime,
2020-12-13 12:37:08 +01:00
);
}
extension ProcessingStateExt on ja.ProcessingState {
ProcessingState toProcessingState() {
switch (this) {
case ja.ProcessingState.loading:
return ProcessingState.loading;
case ja.ProcessingState.buffering:
return ProcessingState.buffering;
case ja.ProcessingState.ready:
return ProcessingState.ready;
case ja.ProcessingState.completed:
return ProcessingState.completed;
default:
return ProcessingState.none;
}
}
}