NetCoreAudio
repository·master·Indexed 40 days ago
https://github.com/mobiletechtracker/netcoreaudioA cross-platform .NET library for audio playback and recording that provides a unified API for Windows, macOS, and Linux. It features a Player class for controlling playback (Play, Pause, Resume, Stop, SetVolume) and a Recorder class for capturing audio to files. The library abstracts OS-specific implementations such as ALSA on Linux and afplay on macOS.
What's inside NetCoreAudio
- NetCoreAudio can be installed as a standard NuGet package. It is designed to work across Windows, macOS, and Linux on various CPU architectures (AMD, ARM, etc.) with minimal dependencies.
Add and configure assets in an Uno Platform project
masterTo use images or other assets in an Uno Platform project, follow these steps:
- Add the asset file to the
Assetsdirectory of your shared project. - Set the Build Action for the file to
Content. - To ensure high-quality rendering across different devices, provide assets for various scales/DPIs using the naming conventions or directory structures supported by the target platforms.
// Example file structure for scaled assets \Assets\Images\logo.scale-100.png \Assets\Images\logo.scale-200.png \Assets\Images\logo.scale-400.png- Add the asset file to the
Configure OS-specific dependencies for NetCoreAudio
masterWhile Windows requires no additional prerequisites, macOS and Linux require specific utilities to enable playback and recording functionality.
macOS Dependencies
- Playback: Uses
afplay(included by default in macOS). - Recording: Requires
ffmpegto be installed.
Linux Dependencies
Linux implementation relies on the ALSA architecture. The following utilities must be installed:
- Playback (non-MP3):
aplay - Volume Control:
amixer - Recording:
arecord - MP3 Playback:
mpg123
- Playback: Uses
Explore NetCoreAudio usage samples
masterTheSamplesdirectory contains various code implementations demonstrating how to integrateNetCoreAudiointo different application architectures and types. Use these projects to understand implementation patterns for specific frameworks.Use NetCoreAudio in an Uno MVVM application
masterTheUnoMvvmAudioPlayerproject provides a concrete example of how to implement audio functionality within an UNO MVVM application architecture. This is useful for developers building cross-platform UI applications using the Uno Platform and the MVVM pattern.Use the Player class for audio playback
masterThe
Playerclass abstracts OS-specific audio playback implementations. It automatically detects the host operating system at runtime.Properties
bool Playing: True if audio is currently playing.bool Paused: True if audio playback is currently paused.
Methods
Task Play(string fileName): Stops current playback and starts playing the specified file (absolute or relative path). SetsPlayingtotrueandPausedtofalse.Task Pause(): Pauses ongoing playback. SetsPausedtotrue. Does not change thePlayingflag.Task Resume(): Resumes paused playback. SetsPausedtofalse. Does not change thePlayingflag.Task Stop(): Stops playback and clears the buffer. Sets bothPlayingandPausedtofalse. Note: Stopped playback cannot be resumed; you must callPlayagain to restart from the beginning.Task SetVolume(): Sets the playback volume as a percentage.
Events
EventHandler PlaybackFinished: Triggered when playback completes. Internally sets thePlayingflag tofalse.
Use the Recorder class for audio recording
masterThe
Recorderclass provides functionality to capture audio and save it to a file.Properties
bool Recording: Indicates if an audio recording session is currently active.
Methods
Task Record(string fileName): Begins recording audio into the specified file.Task Stop(): Stops the recording and saves the captured data to the file specified in theRecordmethod.
Configure routing and cache-control headers
masterThe
routesarray allows you to define specific caching behaviors for different file patterns usingcache-controlheaders:- Packages: Files matching
/package_*are set topublic, immutable, max-age=31536000(1 year). - Fonts: Files matching
/*.ttfare set topublic, immutable, max-age=31536000(1 year). - Default: All other paths (
/*) are set tomust-revalidate, max-age=3600(1 hour).
"routes": [ { "route": "/package_*", "headers": { "cache-control": "public, immutable, max-age=31536000" } }, { "route": "/*.ttf", "headers": { "cache-control": "public, immutable, max-age=31536000" } }, { "route": "/*", "headers": { "cache-control": "must-revalidate, max-age=3600" } } ]- Packages: Files matching
Configure navigation fallback for Static Web Apps
masterThe
navigationFallbackconfiguration defines how the application handles requests for paths that do not match an existing file. In this setup, all non-excluded requests are rewritten to/index.html, which is a common requirement for Single Page Applications (SPAs) to allow client-side routing to take over."navigationFallback": { "rewrite": "/index.html", "exclude": [ "*.{css,js}", "*.{png}", "*.{c,h,wasm,clr,pdb,dat,txt}" ] }Scale and DPI mapping for assets across platforms
masterWhen providing assets for different screen densities, use the following mapping to ensure compatibility across WinUI, iOS/MacCatalyst, and Android:
Scale WinUI iOS/MacCatalyst Android 100scale-100@1xmdpi125scale-125N/A N/A 150scale-150N/A hdpi200scale-200@2xxhdpi300scale-300@3xxxhdpi400scale-400N/A xxxhdpi