new audio player configured
This commit is contained in:
parent
7303234c81
commit
ae560b90a0
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:didvan/constants/assets.dart';
|
||||
import 'package:didvan/models/requests/studio.dart';
|
||||
import 'package:didvan/models/studio_details_data.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
|
|
@ -19,12 +20,12 @@ class MediaService {
|
|||
static Future<void> handleAudioPlayback({
|
||||
required dynamic audioSource,
|
||||
required int id,
|
||||
bool? isNetworkAudio,
|
||||
bool isNetworkAudio = true,
|
||||
bool isVoiceMessage = true,
|
||||
void Function(bool isNext)? onTrackChanged,
|
||||
}) async {
|
||||
String tag;
|
||||
tag = '${isVoiceMessage ? 'message' : 'podcast'}-$id';
|
||||
isNetworkAudio ??= audioSource.runtimeType == String;
|
||||
if (!isVoiceMessage && MediaProvider.downloadedItemIds.contains(id)) {
|
||||
audioSource = StorageService.appDocsDir + '/podcasts/podcast-$id.mp3';
|
||||
isNetworkAudio = false;
|
||||
|
|
@ -35,27 +36,45 @@ class MediaService {
|
|||
}
|
||||
await audioPlayer.stop();
|
||||
audioPlayerTag = tag;
|
||||
Audio audio;
|
||||
String source;
|
||||
if (isNetworkAudio) {
|
||||
await audioPlayer.open(
|
||||
Audio.network(
|
||||
isVoiceMessage
|
||||
? (RequestHelper.baseUrl +
|
||||
if (isVoiceMessage) {
|
||||
source = RequestHelper.baseUrl +
|
||||
audioSource +
|
||||
'?accessToken=${RequestService.token}')
|
||||
: audioSource,
|
||||
'?accessToken=${RequestService.token}';
|
||||
} else {
|
||||
source = audioSource;
|
||||
}
|
||||
audio = Audio.network(
|
||||
kIsWeb ? source.replaceAll('%3A', ':') : source,
|
||||
metas: isVoiceMessage
|
||||
? null
|
||||
: Metas(
|
||||
artist: 'استودیو دیدوان',
|
||||
title: currentPodcast!.title,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if (kIsWeb) {
|
||||
await audioPlayer.open(
|
||||
Audio.network(audioSource!.replaceAll('%3A', ':')),
|
||||
audio = Audio.file(
|
||||
audioSource,
|
||||
metas: isVoiceMessage
|
||||
? null
|
||||
: Metas(
|
||||
artist: 'استودیو دیدوان',
|
||||
title: currentPodcast!.title,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await audioPlayer.open(Audio.file(audioSource));
|
||||
}
|
||||
}
|
||||
audioPlayer.play();
|
||||
audioPlayer.updateCurrentAudioNotification();
|
||||
await audioPlayer.open(
|
||||
audio,
|
||||
showNotification: !isVoiceMessage,
|
||||
notificationSettings: NotificationSettings(
|
||||
customStopAction: (_) => resetAudioPlayer(),
|
||||
customNextAction: (_) => onTrackChanged?.call(true),
|
||||
customPrevAction: (_) => onTrackChanged?.call(false),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> resetAudioPlayer() async {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/overview_data.dart';
|
||||
|
|
@ -38,7 +39,7 @@ class StudioDetailsState extends CoreProvier {
|
|||
int id, {
|
||||
StudioRequestArgs? args,
|
||||
bool? isForward,
|
||||
bool forceFetch = false,
|
||||
bool fetchOnly = false,
|
||||
}) async {
|
||||
if (args != null) {
|
||||
this.args = args;
|
||||
|
|
@ -48,7 +49,7 @@ class StudioDetailsState extends CoreProvier {
|
|||
}
|
||||
if (MediaService.currentPodcast?.id == id &&
|
||||
this.args.type == 'podcast' &&
|
||||
!forceFetch) {
|
||||
!fetchOnly) {
|
||||
return;
|
||||
}
|
||||
_selectedDetailsIndex = 0;
|
||||
|
|
@ -67,7 +68,8 @@ class StudioDetailsState extends CoreProvier {
|
|||
}
|
||||
if (isForward == null) {
|
||||
if (this.args.type == 'podcast') {
|
||||
MediaService.audioPlayerTag = 'podcast';
|
||||
MediaService.audioPlayerTag =
|
||||
'podcast-${MediaService.currentPodcast?.id ?? ''}';
|
||||
}
|
||||
appState = AppState.busy;
|
||||
} else {
|
||||
|
|
@ -91,7 +93,7 @@ class StudioDetailsState extends CoreProvier {
|
|||
if (result['prevStudio'].isNotEmpty && this.args.page != 0) {
|
||||
prevStudio = StudioDetailsData.fromJson(result['prevStudio']);
|
||||
}
|
||||
if (isForward == null && !forceFetch) {
|
||||
if (isForward == null && !fetchOnly) {
|
||||
await _handlePodcastPlayback(studio);
|
||||
}
|
||||
alongSideState = AppState.idle;
|
||||
|
|
@ -114,6 +116,13 @@ class StudioDetailsState extends CoreProvier {
|
|||
audioSource: studio.link,
|
||||
id: studio.id,
|
||||
isVoiceMessage: false,
|
||||
onTrackChanged: (isNext) {
|
||||
if (isNext && nextStudio != null) {
|
||||
getStudioDetails(nextStudio!.id);
|
||||
} else if (!isNext && prevStudio != null) {
|
||||
getStudioDetails(prevStudio!.id);
|
||||
}
|
||||
},
|
||||
);
|
||||
if (nextStudio != null && !_positionListenerActivated) {
|
||||
_positionListenerActivated = true;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:assets_audio_player/assets_audio_player.dart';
|
||||
import 'package:didvan/config/design_config.dart';
|
||||
import 'package:didvan/config/theme_data.dart';
|
||||
|
|
@ -241,7 +243,7 @@ class _PlayerNavBar extends StatelessWidget {
|
|||
state.getStudioDetails(
|
||||
MediaService.currentPodcast!.id,
|
||||
args: state.podcastArgs,
|
||||
forceFetch: true,
|
||||
fetchOnly: true,
|
||||
);
|
||||
}
|
||||
MediaService.handleAudioPlayback(
|
||||
|
|
@ -270,7 +272,7 @@ class _PlayerNavBar extends StatelessWidget {
|
|||
detailsState.getStudioDetails(
|
||||
MediaService.currentPodcast!.id,
|
||||
args: detailsState.podcastArgs,
|
||||
forceFetch: true,
|
||||
fetchOnly: true,
|
||||
);
|
||||
}
|
||||
final state = context.read<StudioState>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue