NetCoreAudio

repository·master·Indexed 40 days ago

https://github.com/mobiletechtracker/netcoreaudio

A 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.

Tokens
1.4K
Snippets
3
Records
10
Agent score
100%

What's inside NetCoreAudio

  1. Add and configure assets in an Uno Platform project

    master

    To use images or other assets in an Uno Platform project, follow these steps:

    1. Add the asset file to the Assets directory of your shared project.
    2. Set the Build Action for the file to Content.
    3. 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
  2. Configure OS-specific dependencies for NetCoreAudio

    master

    While 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 ffmpeg to 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
  3. Use the Player class for audio playback

    master

    The Player class 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). Sets Playing to true and Paused to false.
    • Task Pause(): Pauses ongoing playback. Sets Paused to true. Does not change the Playing flag.
    • Task Resume(): Resumes paused playback. Sets Paused to false. Does not change the Playing flag.
    • Task Stop(): Stops playback and clears the buffer. Sets both Playing and Paused to false. Note: Stopped playback cannot be resumed; you must call Play again to restart from the beginning.
    • Task SetVolume(): Sets the playback volume as a percentage.

    Events

    • EventHandler PlaybackFinished: Triggered when playback completes. Internally sets the Playing flag to false.
  4. Use the Recorder class for audio recording

    master

    The Recorder class 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 the Record method.
  5. Configure routing and cache-control headers

    master

    The routes array allows you to define specific caching behaviors for different file patterns using cache-control headers:

    • Packages: Files matching /package_* are set to public, immutable, max-age=31536000 (1 year).
    • Fonts: Files matching /*.ttf are set to public, immutable, max-age=31536000 (1 year).
    • Default: All other paths (/*) are set to must-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"
        }
      }
    ]
  6. Configure navigation fallback for Static Web Apps

    master

    The navigationFallback configuration 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}"
      ]
    }