mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-15 10:15:58 -07:00
feat: Sync offline/online playback when able (#431)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
15ac3566e2
commit
092836328f
42 changed files with 1002 additions and 497 deletions
|
|
@ -66,35 +66,36 @@ class OfflinePlaybackModel extends PlaybackModel {
|
|||
|
||||
@override
|
||||
Future<PlaybackModel?> playbackStopped(Duration position, Duration? totalDuration, Ref ref) async {
|
||||
final progress = position.inMilliseconds / (item.overview.runTime?.inMilliseconds ?? 0) * 100;
|
||||
final isPlayed = UserData.isPlayed(position, item.overview.runTime ?? Duration.zero);
|
||||
final userData = syncedItem.userData?.copyWith(
|
||||
playbackPositionTicks: isPlayed != false ? 0 : position.toRuntimeTicks,
|
||||
progress: isPlayed != false ? 0.0 : progress,
|
||||
played: isPlayed,
|
||||
lastPlayed: DateTime.now().toUtc(),
|
||||
);
|
||||
final newItem = syncedItem.copyWith(
|
||||
userData: userData,
|
||||
);
|
||||
await ref.read(syncProvider.notifier).updateItem(newItem);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PlaybackModel?> updatePlaybackPosition(Duration position, bool isPlaying, Ref ref) async {
|
||||
final progress = position.inMilliseconds / (item.overview.runTime?.inMilliseconds ?? 0) * 100;
|
||||
final isPlayed = UserData.isPlayed(position, item.overview.runTime ?? Duration.zero);
|
||||
final userData = syncedItem.userData?.copyWith(
|
||||
playbackPositionTicks: isPlayed != false ? 0 : position.toRuntimeTicks,
|
||||
progress: isPlayed != false ? 0.0 : progress,
|
||||
played: isPlayed,
|
||||
lastPlayed: DateTime.now().toUtc(),
|
||||
);
|
||||
final newItem = syncedItem.copyWith(
|
||||
userData: syncedItem.userData?.copyWith(
|
||||
playbackPositionTicks: position.toRuntimeTicks,
|
||||
progress: progress,
|
||||
played: isPlayed(position, item.overview.runTime ?? Duration.zero),
|
||||
),
|
||||
userData: userData,
|
||||
);
|
||||
await ref.read(syncProvider.notifier).updateItem(newItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
bool isPlayed(Duration position, Duration totalDuration) {
|
||||
Duration startBuffer = totalDuration * 0.05;
|
||||
Duration endBuffer = totalDuration * 0.90;
|
||||
|
||||
Duration validStart = startBuffer;
|
||||
Duration validEnd = endBuffer;
|
||||
|
||||
if (position >= validStart && position <= validEnd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue