gdelataillade/alarm

Is it possible to set the alarm sound to other downloaded audio files besides the ones in assets?

Closed this issue · 7 comments

It looks like the "assetAudioPath" is only set to the audio that is in the asset.

It would be nice to be able to set the alarm sound to other audio file downloaded by the app and stored in the internal folder of getApplicationDocumentsDirectory().

i use it like this, and it works well:

assetAudioPath: "((await getApplicationCacheDirectory()).path)/yourFileName.mp3"

should be the same with the documents dir as well :)
also if you didnt, you need to add android.permission.READ_EXTERNAL_STORAGE to AndroidManifest for it to work

If you downloaded the file in app documents folder, it should also work with just:

assetAudioPath: 'yourFileName.mp3'

In case of iOS(iPhone), it seems not work properly.

Unhandled Exception: PlatformException(NATIVE_ERR, [SwiftAlarmPlugin] Failed to load audio for asset: /var/mobile/Containers/Data/Application/E38AF61B-7928-4B53-A167-F6FF3D9/Documents/7051157.m4a, null, null)
IOSAlarm.setAlarm (package:alarm/src/ios_alarm.dart:64:7)

Hi @wann2

Did you use getApplicationDocumentsDirectory to build the path ?

Yes, I used getApplicationDocumentsDirectory, but it seems not work in iPhone. it happens the error.

final Directory directoryDir = await getApplicationDocumentsDirectory();
final alarmSettings = AlarmSettings(
id: alarmId,
dateTime: DateTime(calcDT.year, calcDT.month, calcDT.day, selectedDT.hour, selectedDT.minute, 0, 0, 0),
loopAudio: loopAudio,
vibrate: vibrate,
volume: volume,
assetAudioPath: '${documentsDir.path}/${path.basename(alarmAudio!.path)}',
notificationTitle: title,
notificationBody: body,
enableNotificationOnKill: true,
);
await Alarm.set(alarmSettings: alarmSettings)
...
Unhandled Exception: PlatformException(NATIVE_ERR, [SwiftAlarmPlugin] Failed to load audio for asset: /var/mobile/Containers/Data/Application/E38AF61B-7928-4B53-A167-F6FF3D9/Documents/7051157.m4a, null, null)
IOSAlarm.setAlarm (package:alarm/src/ios_alarm.dart:64:7)

@wann2

Have you tried just passing the filename ? Like I said here:

If you downloaded the file in app documents folder, it should also work with just:

assetAudioPath: 'yourFileName.mp3'

I just put the music filename in assetAudioPath without the getApplicationDocumentsDirectory path and it works fine.
Thank you very much.