Skip to content

[Windows] How to play a custom sound? #2510

@JulienDev

Description

@JulienDev

Describe the bug
Hello, I’m trying to play a custom sound on Windows, but nothing I’ve tried is working. The README doesn’t explain how this should be achieved, and the example project _showNotificationCustomSound() only plays a preset sound: WindowsNotificationAudio.preset(sound: WindowsNotificationSound.alarm5).

In the source code, I noticed a function that allows playing a sound from a URI: WindowsNotificationAudio.fromFile. However, I’m unsure of the exact path format required or how to test it. Additionally, in the allowedSchemes, I see that only ms-appx and ms-resource are supported. Does this mean I need to package it as an MSIX?

Any documentation or sample code would be great :)

To Reproduce

  • Create a new notification with an audio file:
WindowsNotificationDetails(
        audio: WindowsNotificationAudio.fromFile(file: Uri.parse("ms-appx://data/flutter_assets/assets/custom_sound.mp3"))
      )
  • Error in the console:
flutter: Error :  Unsupported operation: Cannot extract a file path from a ms-appx URI
flutter: StackTrace :  #0      _SimpleUri.toFilePath (dart:core/uri.dart:4905:7)
#1      new WindowsNotificationAudio.fromFile (package:flutter_local_notifications_windows/src/details/notification_audio.dart:109:23)
#2      LocalNotificationsManager.schedule (package:projects/data/notifications/local_notifications_manager.dart:103:41)
#3      AlarmsManager.schedulePrayer (package:projects/data/alarms/alarms_manager.dart:118:28)
#4      AlarmsManager.showTestPrayer (package:projects/data/alarms/alarms_manager.dart:69:5)

Expected behavior
The custom sound should be played

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions