generateAssetUri static method
Implementation
static Future<String> generateAssetUri(String asset) async {
if (Platform.isAndroid) {
// read local asset from rootBundle
final byteData = await rootBundle.load(asset);
// create a temporary file on the device to be read by the native side
final file = File('${(await getTemporaryDirectory()).path}/$asset');
await file.create(recursive: true);
await file.writeAsBytes(byteData.buffer.asUint8List());
return file.uri.path;
} else if (Platform.isIOS) {
if (!['wav', 'mp3', 'aiff', 'caf']
.contains(asset.split('.').last.toLowerCase())) {
throw 'Format not supported for iOS. Only mp3, wav, aiff and caf formats are supported.';
}
return asset;
} else {
return asset;
}
}