mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-13 09:20:31 -07:00
fix: Incorrect playback reporting (#221)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
f259151336
commit
3b4b8a9101
5 changed files with 13 additions and 27 deletions
|
|
@ -110,9 +110,7 @@ class DirectPlaybackModel implements PlaybackModel {
|
||||||
mediaSourceId: item.id,
|
mediaSourceId: item.id,
|
||||||
playSessionId: playbackInfo.playSessionId,
|
playSessionId: playbackInfo.playSessionId,
|
||||||
positionTicks: position.toRuntimeTicks,
|
positionTicks: position.toRuntimeTicks,
|
||||||
failed: false,
|
|
||||||
),
|
),
|
||||||
totalDuration: totalDuration,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,7 @@ class TranscodePlaybackModel implements PlaybackModel {
|
||||||
mediaSourceId: item.id,
|
mediaSourceId: item.id,
|
||||||
playSessionId: playbackInfo.playSessionId,
|
playSessionId: playbackInfo.playSessionId,
|
||||||
positionTicks: position.toRuntimeTicks,
|
positionTicks: position.toRuntimeTicks,
|
||||||
failed: false,
|
|
||||||
),
|
),
|
||||||
totalDuration: totalDuration,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import 'package:fladder/models/items/trick_play_model.dart';
|
||||||
import 'package:fladder/providers/auth_provider.dart';
|
import 'package:fladder/providers/auth_provider.dart';
|
||||||
import 'package:fladder/providers/image_provider.dart';
|
import 'package:fladder/providers/image_provider.dart';
|
||||||
import 'package:fladder/providers/user_provider.dart';
|
import 'package:fladder/providers/user_provider.dart';
|
||||||
import 'package:fladder/util/duration_extensions.dart';
|
|
||||||
import 'package:fladder/util/jellyfin_extension.dart';
|
import 'package:fladder/util/jellyfin_extension.dart';
|
||||||
|
|
||||||
class ServerQueryResult {
|
class ServerQueryResult {
|
||||||
|
|
@ -492,25 +491,8 @@ class JellyService {
|
||||||
|
|
||||||
Future<Response> sessionsPlayingStoppedPost({
|
Future<Response> sessionsPlayingStoppedPost({
|
||||||
required PlaybackStopInfo? body,
|
required PlaybackStopInfo? body,
|
||||||
Duration? totalDuration,
|
}) =>
|
||||||
}) async {
|
api.sessionsPlayingStoppedPost(body: body);
|
||||||
final position = body?.positionTicks;
|
|
||||||
final totalTime = totalDuration?.toRuntimeTicks;
|
|
||||||
final maxTime = ref.read(userProvider.select((value) => value?.serverConfiguration?.maxResumePct ?? 90));
|
|
||||||
|
|
||||||
final response = await api.sessionsPlayingStoppedPost(
|
|
||||||
body: body?.copyWith(
|
|
||||||
failed: false,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
//This is a temporary fix
|
|
||||||
if (totalTime != null && position != null && position > (totalTime * (maxTime / 100))) {
|
|
||||||
await usersUserIdPlayedItemsItemIdPost(itemId: body?.itemId, datePlayed: DateTime.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Response> sessionsPlayingProgressPost({required PlaybackProgressInfo? body}) async =>
|
Future<Response> sessionsPlayingProgressPost({required PlaybackProgressInfo? body}) async =>
|
||||||
api.sessionsPlayingProgressPost(body: body);
|
api.sessionsPlayingProgressPost(body: body);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class VideoPlayerNotifier extends StateNotifier<MediaControlsWrapper> {
|
||||||
final lastPosition = ref.read(mediaPlaybackProvider.select((value) => value.lastPosition));
|
final lastPosition = ref.read(mediaPlaybackProvider.select((value) => value.lastPosition));
|
||||||
final diff = (position.inMilliseconds - lastPosition.inMilliseconds).abs();
|
final diff = (position.inMilliseconds - lastPosition.inMilliseconds).abs();
|
||||||
|
|
||||||
if (diff > const Duration(seconds: 1, milliseconds: 500).inMilliseconds) {
|
if (diff > const Duration(seconds: 10).inMilliseconds) {
|
||||||
mediaState.update((value) => value.copyWith(
|
mediaState.update((value) => value.copyWith(
|
||||||
position: event,
|
position: event,
|
||||||
playing: playbackState.playing,
|
playing: playbackState.playing,
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,8 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
||||||
processingState: AudioProcessingState.ready,
|
processingState: AudioProcessingState.ready,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
ref.read(playBackModel)?.playbackStarted(currentPosition ?? Duration.zero, ref);
|
||||||
|
|
||||||
return super.play();
|
return super.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,16 +234,22 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
||||||
@override
|
@override
|
||||||
Future<void> stop() async {
|
Future<void> stop() async {
|
||||||
WakelockPlus.disable();
|
WakelockPlus.disable();
|
||||||
final position = _player?.lastState.position;
|
|
||||||
final totalDuration = _player?.lastState.duration;
|
|
||||||
super.stop();
|
super.stop();
|
||||||
_player?.stop();
|
_player?.stop();
|
||||||
|
|
||||||
|
final position = _player?.lastState.position;
|
||||||
|
final totalDuration = _player?.lastState.duration;
|
||||||
|
|
||||||
|
//Small delay so we don't post right after playback/progress update
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
|
||||||
ref.read(playBackModel)?.playbackStopped(position ?? Duration.zero, totalDuration, ref);
|
ref.read(playBackModel)?.playbackStopped(position ?? Duration.zero, totalDuration, ref);
|
||||||
ref.read(mediaPlaybackProvider.notifier).update((state) => state.copyWith(position: Duration.zero));
|
ref.read(mediaPlaybackProvider.notifier).update((state) => state.copyWith(position: Duration.zero));
|
||||||
|
|
||||||
smtc?.setPlaybackStatus(PlaybackStatus.stopped);
|
smtc?.setPlaybackStatus(PlaybackStatus.stopped);
|
||||||
smtc?.clearMetadata();
|
smtc?.clearMetadata();
|
||||||
smtc?.disableSmtc();
|
smtc?.disableSmtc();
|
||||||
|
|
||||||
playbackState.add(
|
playbackState.add(
|
||||||
playbackState.value.copyWith(
|
playbackState.value.copyWith(
|
||||||
playing: false,
|
playing: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue