Hi I'm a newbie for flutter. Plugin - I'm using this plugin.
I'm working on a Flutter project and I'm using Install-time Delivery Asset Packs to manage my assets. I have some MP3 files that are included in the asset pack, and I want to play them in my Flutter application. In light of this, I'm kindly requesting assistance in understanding the correct approach to load and play these MP3 files from an Install-time Delivery Asset Pack in Flutter. Any insights or code snippets would be greatly appreciated.
my pubspec.yaml file like this:
dependencies:
flutter:
sdk: flutter
audioplayers_darwin: ^5.0.1
cupertino_icons: ^1.0.2
just_audio_background: ^0.0.1-beta.10
audio_service: ^0.18.12
just_audio: ^0.9.35
flutter_play_asset_delivery: ^0.0.2
Error :
E/flutter (13059): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Asset file PonSelAudTrai1-1.mp3 not found.
E/flutter (13059): #0 FlutterPlayAssetDelivery.getAssetFile (package:flutter_play_asset_delivery/flutter_play_asset_delivery.dart:17:7)
E/flutter (13059): <asynchronous suspension>
E/flutter (13059):
E/flutter (13059): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Asset file PonSelAudTrai1-2.mp3 not found.
E/flutter (13059): #0 FlutterPlayAssetDelivery.getAssetFile (package:flutter_play_asset_delivery/flutter_play_asset_delivery.dart:17:7)
E/flutter (13059): <asynchronous suspension>
audio.dart:
static int _nextMediaId = 0;
late AudioPlayer _player;
late Future<File> audio_1;
late Future<File> audio_2;
late Future<File> audio_3;
late Future<File> audio_4;
late Future<File> image;
// late String audioFilePath;
late ConcatenatingAudioSource _playlist;
@override
void initState() {
super.initState();
_player = AudioPlayer();
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.black,
));
_init();
_loadAudioAssets();
}
Future<void> _loadAudioAssets() async {
audio_1 = FlutterPlayAssetDelivery.getAssetFile("PonSelAudTrai1-1.mp3");
audio_2 = FlutterPlayAssetDelivery.getAssetFile("PonSelAudTrai1-2.mp3");
audio_3 = FlutterPlayAssetDelivery.getAssetFile("PonSelAudTrai1-3.mp3");
audio_4 = FlutterPlayAssetDelivery.getAssetFile("PonSelAudTrai1-4.mp3");
// audioFilePath = FlutterPlayAssetDelivery.getAssetFile("PonSelAudTrai1-1.mp3") as String;
_playlist = _updatePlaylistPaths();
}
ConcatenatingAudioSource _updatePlaylistPaths() {
return ConcatenatingAudioSource(children: [
ClippingAudioSource(
start: const Duration(seconds: 0),
end: const Duration(seconds: 163),
child: AudioSource.uri(Uri.file("$audio_1")),
// <-- Use the variable here
tag: MediaItem(
id: '${_nextMediaId++}',
album: "",
title: "▶︎ 01 - முன்னோட்டம்",
artUri: Uri.parse(
"https://play-lh.googleusercontent.com/aZ41BkoanL_UP2kMyBuqE7mesewHowGbcl_TjfChnSvpYWyaO7L_84wHOIM_3x247dw=w240-h480-rw"),
),
),
AudioSource.uri(
Uri.parse('$audio_2'),
tag: MediaItem(
id: '${_nextMediaId++}',
album: "",
title: "▶︎ 02 - முன்னோட்டம்",
artUri: Uri.parse(
"https://play-lh.googleusercontent.com/aZ41BkoanL_UP2kMyBuqE7mesewHowGbcl_TjfChnSvpYWyaO7L_84wHOIM_3x247dw=w240-h480-rw"),
),
),
AudioSource.uri(
Uri.parse(
'$audio_3'),
tag: MediaItem(
id: '${_nextMediaId++}',
album: "",
title: "▶︎ 03 - முன்னோட்டம்",
artUri: Uri.parse(
"https://play-lh.googleusercontent.com/aZ41BkoanL_UP2kMyBuqE7mesewHowGbcl_TjfChnSvpYWyaO7L_84wHOIM_3x247dw=w240-h480-rw"),
),
),
AudioSource.uri(
Uri.parse(
'$audio_4'),
tag: MediaItem(
id: '${_nextMediaId++}',
album: "",
title: "▶︎ 04 - முன்னோட்டம்",
artUri: Uri.parse(
"https://play-lh.googleusercontent.com/aZ41BkoanL_UP2kMyBuqE7mesewHowGbcl_TjfChnSvpYWyaO7L_84wHOIM_3x247dw=w240-h480-rw"),
),
),
]);
// setState(() {
// _playlist = _playlist; // Assuming _playlist is a state variable
// });
}
Could someone please guide me on how to correctly load and play these MP3 files from an Install-time Delivery Asset Pack in Flutter?