mirror of
https://github.com/meditohq/medito-app.git
synced 2024-09-11 12:15:46 +03:00
Fix end screen glitch
This commit is contained in:
parent
5281176398
commit
1c0c957132
@ -35,6 +35,7 @@
|
||||
<application
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="Medito"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<activity
|
||||
|
@ -13,7 +13,6 @@ import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.media3.common.AudioAttributes
|
||||
import androidx.media3.common.C
|
||||
@ -90,6 +89,7 @@ class AudioPlayerService : MediaSessionService(), Player.Listener, MeditoAudioSe
|
||||
} else if (!playWhenReady) {
|
||||
backgroundMusicPlayer.pause()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
@ -110,7 +110,6 @@ class AudioPlayerService : MediaSessionService(), Player.Listener, MeditoAudioSe
|
||||
}
|
||||
|
||||
override fun playAudio(audioData: AudioData): Boolean {
|
||||
|
||||
val primaryMediaItem = MediaItem.Builder()
|
||||
.setUri(audioData.url)
|
||||
.setMediaId(audioData.url)
|
||||
@ -212,14 +211,8 @@ class AudioPlayerService : MediaSessionService(), Player.Listener, MeditoAudioSe
|
||||
this.backgroundSoundUri = uri
|
||||
}
|
||||
|
||||
@OptIn(UnstableApi::class)
|
||||
override fun stopBackgroundSound() {
|
||||
backgroundMusicPlayer.stop()
|
||||
NotificationUtil.setNotification(
|
||||
this,
|
||||
NOTIFICATION_ID,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
override fun setBackgroundSoundVolume(volume: Double) {
|
||||
@ -254,8 +247,6 @@ class AudioPlayerService : MediaSessionService(), Player.Listener, MeditoAudioSe
|
||||
override fun stopAudio() {
|
||||
primaryPlayer.stop()
|
||||
backgroundMusicPlayer.stop()
|
||||
handler.removeCallbacks(positionUpdateRunnable)
|
||||
|
||||
}
|
||||
|
||||
override fun playPauseAudio() {
|
||||
|
@ -79,7 +79,7 @@ class DownloadListItemWidget extends StatelessWidget {
|
||||
child: data.icon ??
|
||||
NetworkImageWidget(
|
||||
url: data.cover!,
|
||||
isCache: true,
|
||||
shouldCache: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -26,14 +26,14 @@ class PlayerView extends ConsumerStatefulWidget {
|
||||
|
||||
class _PlayerViewState extends ConsumerState<PlayerView> {
|
||||
bool _endScreenOpened = false;
|
||||
bool _endScreenRecentlyClosed = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var playbackState = ref.watch(audioStateProvider);
|
||||
|
||||
if (playbackState.isCompleted && playbackState.position > 5000) {
|
||||
_resetState();
|
||||
_openEndScreen();
|
||||
_resetState();
|
||||
}
|
||||
|
||||
var currentlyPlayingTrack = ref.watch(playerProvider);
|
||||
@ -125,15 +125,21 @@ class _PlayerViewState extends ConsumerState<PlayerView> {
|
||||
|
||||
void _handleClose(bool _) {
|
||||
_resetState();
|
||||
_stopAudio();
|
||||
ref
|
||||
.read(playerProvider.notifier)
|
||||
.cancelBackgroundThreadForAudioCompleteEvent();
|
||||
_endScreenOpened = false;
|
||||
|
||||
router.pop();
|
||||
}
|
||||
|
||||
void _stopAudio() {
|
||||
ref.read(playerProvider.notifier).stop();
|
||||
}
|
||||
|
||||
void _resetState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ref.read(playerProvider.notifier).stop();
|
||||
ref.read(audioStateProvider.notifier).resetState();
|
||||
});
|
||||
}
|
||||
@ -141,6 +147,7 @@ class _PlayerViewState extends ConsumerState<PlayerView> {
|
||||
void _openEndScreen() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!_endScreenOpened) {
|
||||
_resetState();
|
||||
var currentlyPlayingTrack = ref.read(playerProvider);
|
||||
var endScreen = currentlyPlayingTrack?.endScreen;
|
||||
if (endScreen != null) {
|
||||
@ -150,6 +157,11 @@ class _PlayerViewState extends ConsumerState<PlayerView> {
|
||||
);
|
||||
}
|
||||
_endScreenOpened = true;
|
||||
_endScreenRecentlyClosed = true;
|
||||
|
||||
Future.delayed(Duration(seconds: 2), () {
|
||||
_endScreenRecentlyClosed = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class OverlayCoverImageWidget extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: NetworkImageWidget(
|
||||
url: imageUrl,
|
||||
isCache: true,
|
||||
shouldCache: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -168,7 +168,7 @@ class _TrackViewState extends ConsumerState<TrackView>
|
||||
height: 248,
|
||||
child: NetworkImageWidget(
|
||||
url: trackModel.coverUrl,
|
||||
isCache: true,
|
||||
shouldCache: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -91,7 +91,7 @@ class _MeditoAppBarLargeState extends State<MeditoAppBarLarge> {
|
||||
],
|
||||
),
|
||||
url: coverUrl,
|
||||
isCache: true,
|
||||
shouldCache: true,
|
||||
errorWidget: SizedBox(),
|
||||
),
|
||||
);
|
||||
|
@ -3,6 +3,7 @@ import 'dart:io';
|
||||
import 'package:Medito/constants/constants.dart';
|
||||
import 'package:Medito/models/models.dart';
|
||||
import 'package:Medito/providers/providers.dart';
|
||||
import 'package:Medito/widgets/shimmers/background_sounds_shimmer_widget.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@ -12,7 +13,7 @@ import 'package:shimmer/shimmer.dart';
|
||||
class NetworkImageWidget extends ConsumerWidget {
|
||||
final String url;
|
||||
final double? height, width;
|
||||
final bool isCache;
|
||||
final bool shouldCache;
|
||||
final Gradient? gradient;
|
||||
final Widget? errorWidget;
|
||||
|
||||
@ -21,7 +22,7 @@ class NetworkImageWidget extends ConsumerWidget {
|
||||
required this.url,
|
||||
this.height,
|
||||
this.width,
|
||||
this.isCache = false,
|
||||
this.shouldCache = false,
|
||||
this.gradient,
|
||||
this.errorWidget,
|
||||
}) : super(key: key);
|
||||
@ -38,7 +39,7 @@ class NetworkImageWidget extends ConsumerWidget {
|
||||
width: width,
|
||||
);
|
||||
} else {
|
||||
if (isCache) {
|
||||
if (shouldCache) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: url,
|
||||
httpHeaders: {
|
||||
|
@ -90,7 +90,7 @@ class PackCardWidget extends StatelessWidget {
|
||||
width: 80,
|
||||
child: NetworkImageWidget(
|
||||
url: coverUrlPath ?? '',
|
||||
isCache: true,
|
||||
shouldCache: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user