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