How to add raw resource with mp3 file in flutter

70 Views Asked by At

i have a problem when adding raw resource file in my android flutter project.. and the error appear to me

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(invalid_sound, The resource sound.mp3 could not be found. Please make sure it has been added as a raw resource to your Android head project., null, null)... but i am sure i added sound.mp3 in raw resaurce

This is my code:

   // show a simple notification
  static Future showSimpleNotification({
    required String title,
    required String body,
    required String payload,
  }) async {
    const AndroidNotificationDetails androidNotificationDetails =
    AndroidNotificationDetails('your channel id', 'your channel name',
        channelDescription: 'your channel description',
        sound: RawResourceAndroidNotificationSound('sound.mp3'),
        playSound: true,
        importance: Importance.max,
        priority: Priority.high,
        ticker: 'ticker');
    const NotificationDetails notificationDetails =
    NotificationDetails(android: androidNotificationDetails);
    await _flutterLocalNotificationsPlugin
        .show(0, title, body, notificationDetails, payload: payload);
  }
0

There are 0 best solutions below