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

Khongchai Greesuradej 0 Reputation points


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.

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

1 answer

Sort by: Most helpful
  1. Bruce ( 59,546 Reputation points

    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.

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