Some Ways to Load Audio from Absolute Path with Audio Element?

Khongchai Greesuradej 0 Reputation points
2023-11-06T18:35:54.1766667+00:00

Hi!

I am working on a port of legacy audio processing c# software to .NET MAUI Blazor hybrid. Most of the audio processing in the ported version is done with AudioWorkletProcessor in javascript -- on the audio thread.

Right now, my problem is that I don't want to load everything onto memory and then throw the entire memory buffer at javascript. The audio files can be huge. This can cause up to 3GB+ memory usage. Some of the details I can't say here, but suffice it to say that the user cannot directly select an audio file, which would have solved my problem, we have to load it for them. Via C#. We cannot just bundle the files with the app either because these files can be downloaded from the internet via our website.

My question is, is there a way to just give the absolute path to the javascript thread somehow and have it load it as the source of an audio element from the specified path instead? Or maybe some ways to programmatically write the file in another location accessible to javascript? I see that you can set --allow-file-access-from-files flag, but the documentation of this is a bit lacking.

Much appreciated folks. Thank you.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,500 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,731 Reputation points
    2023-11-07T17:15:14.3466667+00:00

    webviews (like the one hosting blazor) can not access the filesystem directly, they use a file provider to access the filesystem (actually a custom protocol). the default provider for Blazor supports static files from the wwwroot folder. you should support a custom file provider.

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.webview.maui.blazorwebview.createfileprovider?view=net-maui-7.0

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.fileproviders.ifileprovider?view=dotnet-plat-ext-7.0

    your custom file provider could stream from your website, or cache files.