0

I'm using .net Maui and attempting to create audioManager players for a couple of sound files located in the Resources\Sounds folder in the project.

The code is this:

var playerStartSound = audioManager.CreatePlayer(await FileSystem.OpenAppPackageFileAsync("record-start.mp3"));

When it runs, I get an error:

System.IO.FileNotFoundException: 'Could not find file '/private/var/containers/Bundle/Application/3C75FEDB-E70F-43F9-8F37-9AC51D76BB62/MyApp.app/record-start.mp3'.'

I'm not sure if the Resources\Sounds\ should be added to the above path or if the OpenAppPackageFileAsync will search the subfolder s or not?

What am I doing wrong here? How can I access the files located in the MyApp\Resources\Sounds folder?

Zonus
  • 2,313
  • 2
  • 26
  • 48
  • 1
    Resources are not files and cannot be accessed with file I/O. There are numerous existing posts about opening resources in C# – Jason Jun 17 '23 at 02:56
  • Does this answer your question? [how to play an audio file - .NET MAUI](https://stackoverflow.com/questions/72463558/how-to-play-an-audio-file-net-maui) – ToolmakerSteve Jun 17 '23 at 03:11
  • I was working off of that page; I believe I have the code to play the sounds using Plugin.Maui.Audio, but I don't know how to to access the files in the resources folder in the project. And @Jason, I am going off the page that Toolmaker posted as well as the docs for the Plugin.Maui.Audio which shows accessing the files like listed above. But it's now working for me... I'm not seeing any other way to do it, but perhaps I don't know what to search on. Have any suggestions? – Zonus Jun 17 '23 at 22:15
  • 1
    The file needs to be in Resources/Raw with a BuildAction of MauiAssett – Jason Jun 17 '23 at 22:32
  • Thank you @Jason. It's odd that the maui template has a "sounds" folder created automatically, but the sounds need to actually in the raw folder. This worked. Did you want to create an answer here so I can accept? – Zonus Jun 19 '23 at 13:50

1 Answers1

2

The file needs to be in Resources/Raw with a BuildAction of MauiAsset

Jason
  • 86,222
  • 15
  • 131
  • 146