fix: macos build error, mobile player duration and playing state and background disposal of player

This commit is contained in:
Kingkor Roy Tirtho 2023-05-01 10:23:46 +06:00
parent 6430a25870
commit be91e33828
9 changed files with 33 additions and 19 deletions

View File

@ -42,7 +42,8 @@ class AlbumCard extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final playlist = ref.watch(PlaylistQueueNotifier.provider);
final playing = useStream(audioPlayer.playingStream).data ?? false;
final playing =
useStream(audioPlayer.playingStream).data ?? audioPlayer.isPlaying;
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
final queryClient = useQueryClient();
final query = queryClient

View File

@ -44,7 +44,9 @@ class PlayerControls extends HookConsumerWidget {
[]);
final playlist = ref.watch(PlaylistQueueNotifier.provider);
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
final playing = useStream(audioPlayer.playingStream).data ?? false;
final playing =
useStream(audioPlayer.playingStream).data ?? audioPlayer.isPlaying;
final buffering = useStream(audioPlayer.bufferingStream).data ?? true;
final theme = Theme.of(context);

View File

@ -28,7 +28,8 @@ class PlayerOverlay extends HookConsumerWidget {
);
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
final playlist = ref.watch(PlaylistQueueNotifier.provider);
final playing = useStream(audioPlayer.playingStream).data ?? false;
final playing =
useStream(audioPlayer.playingStream).data ?? audioPlayer.isPlaying;
final theme = Theme.of(context);
final textColor = theme.colorScheme.primary;

View File

@ -21,7 +21,8 @@ class PlaylistCard extends HookConsumerWidget {
Widget build(BuildContext context, ref) {
final playlistQueue = ref.watch(PlaylistQueueNotifier.provider);
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
final playing = useStream(audioPlayer.playingStream).data ?? false;
final playing =
useStream(audioPlayer.playingStream).data ?? audioPlayer.isPlaying;
final queryBowl = QueryClient.of(context);
final query = queryBowl.getQuery<List<Track>, dynamic>(
"playlist-tracks/${playlist.id}",

View File

@ -12,10 +12,17 @@ Tuple4<double, Duration, Duration, double> useProgress(WidgetRef ref) {
useStream(audioPlayer.bufferedPositionStream).data?.inSeconds ?? 0;
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
final duration = useStream(audioPlayer.durationStream).data ?? Duration.zero;
// Duration future is needed for getting the duration of the song
// as stream can be null when no event occurs (Mostly needed for android)
final durationFuture = useFuture(audioPlayer.duration);
final duration = useStream(audioPlayer.durationStream).data ??
durationFuture.data ??
Duration.zero;
final positionFuture = useFuture(audioPlayer.position);
final positionSnapshot = useStream(audioPlayer.positionStream);
final position = positionSnapshot.data ?? Duration.zero;
final position =
positionSnapshot.data ?? positionFuture.data ?? Duration.zero;
final sliderMax = duration.inSeconds;
final sliderValue = position.inSeconds;

View File

@ -199,9 +199,10 @@ class SpotubeState extends ConsumerState<Spotube> {
useInitSysTray(ref);
/// For enabling hot reload for audio player
useEffect(() {
return () {
/// For enabling hot reload for audio player
if (!kDebugMode) return;
audioPlayer.dispose();
youtube.close();
};

View File

@ -52,7 +52,7 @@ class SpotubeAudioPlayer {
// stream getters
Stream<Duration> get durationStream {
if (apSupportedPlatform) {
return _audioPlayer!.onDurationChanged;
return _audioPlayer!.onDurationChanged.asBroadcastStream();
} else {
throw UnimplementedError();
}
@ -60,7 +60,7 @@ class SpotubeAudioPlayer {
Stream<Duration> get positionStream {
if (apSupportedPlatform) {
return _audioPlayer!.onPositionChanged;
return _audioPlayer!.onPositionChanged.asBroadcastStream();
} else {
throw UnimplementedError();
}
@ -69,7 +69,7 @@ class SpotubeAudioPlayer {
Stream<Duration> get bufferedPositionStream {
if (apSupportedPlatform) {
// audioplayers doesn't have the capability to get buffered position
return const Stream.empty();
return const Stream<Duration>.empty().asBroadcastStream();
} else {
throw UnimplementedError();
}
@ -77,7 +77,7 @@ class SpotubeAudioPlayer {
Stream<void> get completedStream {
if (apSupportedPlatform) {
return _audioPlayer!.onPlayerComplete;
return _audioPlayer!.onPlayerComplete.asBroadcastStream();
} else {
throw UnimplementedError();
}
@ -87,7 +87,7 @@ class SpotubeAudioPlayer {
if (apSupportedPlatform) {
return _audioPlayer!.onPlayerStateChanged.map((state) {
return state == ap.PlayerState.playing;
});
}).asBroadcastStream();
} else {
throw UnimplementedError();
}
@ -95,7 +95,7 @@ class SpotubeAudioPlayer {
Stream<bool> get bufferingStream {
if (apSupportedPlatform) {
return Stream.value(false);
return Stream.value(false).asBroadcastStream();
} else {
throw UnimplementedError();
}
@ -103,7 +103,8 @@ class SpotubeAudioPlayer {
Stream<PlayerState> get playerStateStream =>
_audioPlayer!.onPlayerStateChanged
.map((state) => PlayerState.fromApPlayerState(state));
.map((state) => PlayerState.fromApPlayerState(state))
.asBroadcastStream();
// regular info getter

View File

@ -11,11 +11,11 @@
<key>com.apple.security.network.client</key>
<true />
<!-- Just Audio Config -->
<key>NSAppTransportSecurity</key>
<!-- <key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true />
</dict>
</dict> -->
<!-- Requires Certification -->
<!-- <key>keychain-access-groups</key>
<array /> -->

View File

@ -6,14 +6,14 @@
<true />
<key>com.apple.security.network.server</key>
<true />
<!-- Just Audio Config -->
<key>com.apple.security.network.client</key>
<true />
<key>NSAppTransportSecurity</key>
<!-- Just Audio Config -->
<!-- <key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true />
</dict>
</dict> -->
<!-- Requires Certification -->
<!-- <key>keychain-access-groups</key>
<array /> -->