### Start Recording with Recorder.Record() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Begins capturing audio to a specified file. If recording is active, the current session is stopped before starting a new one. Sets the Recording property to true. ```csharp using NetCoreAudio; var recorder = new Recorder(); // Record into an absolute path await recorder.Record("/home/user/recordings/session1.wav"); Console.WriteLine($"Recording: {recorder.Recording}"); // True await Task.Delay(3000); // Calling Record() again while recording automatically stops the previous session await recorder.Record("/home/user/recordings/session2.wav"); Console.WriteLine($"Recording: {recorder.Recording}"); // True (new session) await Task.Delay(3000); await recorder.Stop(); ``` -------------------------------- ### NetCoreAudio Player Play Method Examples Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Illustrates how to use the Player.Play() method with both absolute and relative file paths. Calling Play() on an already playing track will stop the current track first. ```csharp using NetCoreAudio; var player = new Player(); // Absolute path await player.Play("/tmp/audio/notification.wav"); // Relative path (resolved relative to the executing assembly location) await player.Play("sounds/alert.mp3"); // Calling Play() while already playing stops the current track first await player.Play("/tmp/audio/track1.wav"); await Task.Delay(2000); await player.Play("/tmp/audio/track2.wav"); // track1 is stopped automatically ``` -------------------------------- ### NetCoreAudio Player Resume Method Example Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Shows how to resume paused audio playback using the Player.Resume() method. This sets the Paused property to false and has no effect if the player is not currently paused. ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); await Task.Delay(2000); await player.Pause(); Console.WriteLine($"Paused: {player.Paused}"); // True await Task.Delay(1000); // wait before resuming await player.Resume(); Console.WriteLine($"Paused: {player.Paused}"); // False Console.WriteLine($"Playing: {player.Playing}"); // True ``` -------------------------------- ### Register and Use IPlayer and IRecorder with Dependency Injection Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Register IPlayer and IRecorder with your DI container. Consume them via constructor injection. This example shows registration and basic consumption. ```csharp using Microsoft.Extensions.DependencyInjection; using NetCoreAudio; using NetCoreAudio.Interfaces; // Registration var services = new ServiceCollection(); services.AddSingleton(); services.AddSingleton(); var provider = services.BuildServiceProvider(); // Consumption var player = provider.GetRequiredService(); await player.Play("/tmp/audio/welcome.wav"); // Unit test mock example (using Moq) // var mockPlayer = new Mock(); // mockPlayer.Setup(p => p.Play(It.IsAny())).Returns(Task.CompletedTask); // mockPlayer.SetupGet(p => p.Playing).Returns(true); ``` -------------------------------- ### Recorder.Record(string fileName) Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Starts capturing audio and saves it to the specified file. If recording is already in progress, the current session is stopped before the new one begins. ```APIDOC ## Recorder.Record(string fileName) ### Description Begins capturing audio into the specified file. If recording is already in progress, it stops the current session before starting the new one. Sets `Recording = true`. The `fileName` parameter accepts an absolute or relative path. ### Method ```csharp await recorder.Record(string fileName); ``` ### Parameters #### Path Parameters - **fileName** (string) - Required - The path to the file where the audio will be saved. ### Usage Example ```csharp using NetCoreAudio; var recorder = new Recorder(); // Record into an absolute path await recorder.Record("/home/user/recordings/session1.wav"); Console.WriteLine($"Recording: {recorder.Recording}"); // True await Task.Delay(3000); // Calling Record() again while recording automatically stops the previous session await recorder.Record("/home/user/recordings/session2.wav"); Console.WriteLine($"Recording: {recorder.Recording}"); // True (new session) await Task.Delay(3000); await recorder.Stop(); ``` ``` -------------------------------- ### NetCoreAudio Player API Usage Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Demonstrates basic usage of the Player class for audio playback, including event handling, playback control, volume adjustment, and stopping playback. Ensure the NetCoreAudio NuGet package is installed. ```csharp using NetCoreAudio; var player = new Player(); // Subscribe to the playback-finished event player.PlaybackFinished += (sender, args) => { Console.WriteLine("Track finished playing."); }; // Play a file (absolute or relative path) await player.Play("/home/user/music/sample.wav"); Console.WriteLine(player.Playing); // True Console.WriteLine(player.Paused); // False // Pause playback await player.Pause(); Console.WriteLine(player.Paused); // True // Resume playback await player.Resume(); Console.WriteLine(player.Paused); // False // Change volume (0–100) await player.SetVolume(75); // Stop playback entirely (cannot be resumed — must call Play() again) await player.Stop(); Console.WriteLine(player.Playing); // False ``` -------------------------------- ### Loading Fonts from Assets Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/Samples/UnoMvvmAudioPlayer/AudioPlayer.Mobile/Android/Assets/AboutAssets.txt Some Android functions can automatically load asset files. This example shows how to load a font file from the assets directory. ```csharp Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); ``` -------------------------------- ### NetCoreAudio Player Pause Method Example Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Demonstrates pausing audio playback using the Player.Pause() method. This method pauses ongoing playback without clearing the buffer and sets the Paused property to true. ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); await Task.Delay(3000); // listen for 3 seconds await player.Pause(); Console.WriteLine($"Playing: {player.Playing}"); // True Console.WriteLine($"Paused: {player.Paused}"); // True ``` -------------------------------- ### Player.Play(string fileName) Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Starts audio playback for the specified file. If playback is already in progress, the current track is stopped before the new file begins playing. Supports both absolute and relative file paths. ```APIDOC ## Player.Play(string fileName) — Start Playback Stops any current playback and immediately starts playing the specified file. Accepts an absolute path or a path relative to the library's directory. Sets `Playing = true` and `Paused = false`. On Linux, MP3 files are routed through `mpg123`; all other formats use `aplay`. ```csharp using NetCoreAudio; var player = new Player(); // Absolute path await player.Play("/tmp/audio/notification.wav"); // Relative path (resolved relative to the executing assembly location) await player.Play("sounds/alert.mp3"); // Calling Play() while already playing stops the current track first await player.Play("/tmp/audio/track1.wav"); await Task.Delay(2000); await player.Play("/tmp/audio/track2.wav"); // track1 is stopped automatically ``` ``` -------------------------------- ### Audio Recording with Recorder Class Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/README.md The Recorder class is used for audio recording. It allows users to start and stop recording to a specified file. ```APIDOC ## Recorder Class ### Description Provides functionality for recording audio. ### Properties * `bool Recording`: Indicates if audio is currently being recorded. ### Methods * `Task Record(string fileName)`: Begins recording audio into the specified file. * `Task Stop()`: Stops the recording and saves the data to the previously specified file. ``` -------------------------------- ### Generated R Class for Resource IDs Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/Samples/UnoMvvmAudioPlayer/AudioPlayer.Mobile/Android/Resources/AboutResources.txt Shows an example of the 'R' class generated by the Android build system. This class contains static members that map resource names to their corresponding integer IDs, used by native Android APIs. ```csharp public class R { public class drawable { public const int icon = 0x123; } public class layout { public const int main = 0x456; } public class strings { public const int first_string = 0xabc; public const int second_string = 0xbcd; } } ``` -------------------------------- ### Image Asset Naming Conventions Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/Samples/UnoMvvmAudioPlayer/AudioPlayer/Assets/SharedAssets.md Use these naming conventions for image assets to support different scales in Uno Platform projects. Place files in the Assets directory and set their build action to Content. ```text \Assets\Images\logo.scale-100.png \Assets\Images\logo.scale-200.png \Assets\Images\logo.scale-400.png ``` ```text \Assets\Images\scale-100\logo.png \Assets\Images\scale-200\logo.png \Assets\Images\scale-400\logo.png ``` -------------------------------- ### Initialize and Use Recorder for Audio Capture Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Instantiates the Recorder class for capturing audio input. Subscribes to the RecordingFinished event to handle post-recording actions. ```csharp using NetCoreAudio; var recorder = new Recorder(); // Subscribe to the recording-finished event recorder.RecordingFinished += (sender, args) => { Console.WriteLine("Recording saved."); }; // Start recording into a file await recorder.Record("/tmp/recordings/voice_note.wav"); Console.WriteLine($"Recording: {recorder.Recording}"); // True // Wait for some duration (e.g., 5 seconds) await Task.Delay(5000); // Stop and save the recording await recorder.Stop(); Console.WriteLine($"Recording: {recorder.Recording}"); // False ``` -------------------------------- ### Player.SetVolume(byte percent) Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Sets the system or player volume to a specified percentage (0-100). An `ArgumentOutOfRangeException` is thrown if the percentage exceeds 100. ```APIDOC ## Player.SetVolume(byte percent) ### Description Sets the system or player volume as a percentage (0–100). Throws `ArgumentOutOfRangeException` if `percent > 100`. Implementation is OS-specific: Windows uses the MCI volume API, macOS uses `osascript`, and Linux uses `amixer -M set 'Master'`. ### Method ```csharp await player.SetVolume(byte percent); ``` ### Parameters #### Path Parameters - **percent** (byte) - Required - The volume level from 0 to 100. ### Usage Example ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); // Set volume to 50% await player.SetVolume(50); // Mute await player.SetVolume(0); // Full volume await player.SetVolume(100); // Throws ArgumentOutOfRangeException try { await player.SetVolume(150); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine($"Error: {ex.Message}"); // "Percent can't exceed 100 (Parameter 'percent')" } ``` ``` -------------------------------- ### Set Playback Volume with Player.SetVolume() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Adjusts the system or player volume. Accepts a percentage from 0 to 100. Values outside this range will throw an ArgumentOutOfRangeException. ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); // Set volume to 50% await player.SetVolume(50); // Mute await player.SetVolume(0); // Full volume await player.SetVolume(100); // Throws ArgumentOutOfRangeException try { await player.SetVolume(150); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine($"Error: {ex.Message}"); // "Percent can't exceed 100 (Parameter 'percent')" } ``` -------------------------------- ### Audio Playback with Player Class Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/README.md The Player class handles audio playback. It detects the operating system and abstracts OS-specific implementations. It provides methods to play, pause, resume, stop, and set the volume of audio files. ```APIDOC ## Player Class ### Description Provides functionality for playing audio files. ### Properties * `bool Playing`: Indicates if audio is currently playing. * `bool Paused`: Indicates if audio playback is currently paused. ### Methods * `Task Play(string fileName)`: Stops current playback and starts playing the specified audio file. Sets `Playing` to true and `Paused` to false. * `Task Pause()`: Pauses ongoing playback. Sets `Paused` to true. * `Task Resume()`: Resumes paused playback. Sets `Paused` to false. * `Task Stop()`: Stops current playback and clears the buffer. Sets `Playing` and `Paused` to false. * `Task SetVolume()`: Sets the playback volume as a percentage. ### Events * `EventHandler PlaybackFinished`: Triggered when playback finishes. Internally sets `Playing` to false. ``` -------------------------------- ### Recorder Class Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Handles audio input capture from the microphone. It automatically selects the appropriate OS-specific implementation for recording. ```APIDOC ## Recorder Class ### Description The `Recorder` class handles microphone/audio input capture. It auto-selects the OS-appropriate implementation at construction time. On Windows, it uses MCI waveaudio (16-bit, stereo, 48 kHz). On Linux it uses `arecord`, and on macOS it uses `ffmpeg`. A `RecordingFinished` event fires when recording stops. ### Constructor ```csharp var recorder = new Recorder(); ``` ### Usage Example ```csharp using NetCoreAudio; var recorder = new Recorder(); // Subscribe to the recording-finished event recorder.RecordingFinished += (sender, args) => { Console.WriteLine("Recording saved."); }; // Start recording into a file await recorder.Record("/tmp/recordings/voice_note.wav"); Console.WriteLine($"Recording: {recorder.Recording}"); // True // Wait for some duration (e.g., 5 seconds) await Task.Delay(5000); // Stop and save the recording await recorder.Stop(); Console.WriteLine($"Recording: {recorder.Recording}"); // False ``` ``` -------------------------------- ### Accessing Raw Assets with AssetManager Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/Samples/UnoMvvmAudioPlayer/AudioPlayer.Mobile/Android/Assets/AboutAssets.txt Use this pattern to open and read raw asset files deployed with your Android application. Ensure the file has a 'AndroidAsset' build action. ```csharp public class ReadAsset : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); InputStream input = Assets.Open ("my_asset.txt"); } } ``` -------------------------------- ### Player Class Overview Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt The Player class is the primary interface for audio playback. It automatically selects the appropriate platform-specific implementation (Windows, Linux, macOS) and provides methods for controlling playback, managing volume, and handling playback completion events. ```APIDOC ## Player Class The `Player` class is the main entry point for audio playback. It auto-selects `WindowsPlayer`, `LinuxPlayer`, or `MacPlayer` based on the runtime OS. It exposes state properties (`Playing`, `Paused`) and async control methods, plus a `PlaybackFinished` event that fires when a track ends naturally. ```csharp using NetCoreAudio; var player = new Player(); // Subscribe to the playback-finished event player.PlaybackFinished += (sender, args) => { Console.WriteLine("Track finished playing."); }; // Play a file (absolute or relative path) await player.Play("/home/user/music/sample.wav"); Console.WriteLine(player.Playing); // True Console.WriteLine(player.Paused); // False // Pause playback await player.Pause(); Console.WriteLine(player.Paused); // True // Resume playback await player.Resume(); Console.WriteLine(player.Paused); // False // Change volume (0–100) await player.SetVolume(75); // Stop playback entirely (cannot be resumed — must call Play() again) await player.Stop(); Console.WriteLine(player.Playing); // False ``` ``` -------------------------------- ### Player.Resume() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Resumes audio playback that was previously paused. Sets the `Paused` property to false. If the player is not currently paused, this method has no effect. ```APIDOC ## Player.Resume() — Resume Paused Playback Resumes a paused playback session from where it was paused. Sets `Paused = false`; does not modify `Playing`. Has no effect if the player is not currently paused. ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); await Task.Delay(2000); await player.Pause(); Console.WriteLine($"Paused: {player.Paused}"); // True await Task.Delay(1000); // wait before resuming await player.Resume(); Console.WriteLine($"Paused: {player.Paused}"); // False Console.WriteLine($"Playing: {player.Playing}"); // True ``` ``` -------------------------------- ### Stop and Save Recording with Recorder.Stop() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Halts the current audio recording session and saves the captured data to the specified file. Sets the Recording property to false and triggers the RecordingFinished event. Has no effect if not currently recording. ```csharp using NetCoreAudio; var recorder = new Recorder(); recorder.RecordingFinished += (sender, args) => Console.WriteLine("File saved successfully."); await recorder.Record("/tmp/output.wav"); await Task.Delay(10000); // record for 10 seconds await recorder.Stop(); // Output: "File saved successfully." Console.WriteLine($"Recording: {recorder.Recording}"); // False ``` -------------------------------- ### Android Resource Directory Structure Source: https://github.com/mobiletechtracker/netcoreaudio/blob/master/Samples/UnoMvvmAudioPlayer/AudioPlayer.Mobile/Android/Resources/AboutResources.txt Illustrates the standard directory layout for Android resources within an application. Resources are organized into subdirectories like drawable, layout, and values. ```plaintext Resources/ drawable/ icon.png layout/ main.axml values/ strings.xml ``` -------------------------------- ### Player.Stop() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Stops the current audio playback and clears the buffer. After stopping, playback cannot be resumed and requires a new call to `Play()` to restart. ```APIDOC ## Player.Stop() ### Description Stops playback and clears the buffer. Sets both `Playing` and `Paused` to `false`. Stopped playback cannot be resumed — `Play()` must be called again to replay the file. On Windows, temporary MCI files are also cleaned up. ### Method ```csharp await player.Stop(); ``` ### Usage Example ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); await Task.Delay(5000); await player.Stop(); Console.WriteLine($"Playing: {player.Playing}"); // False Console.WriteLine($"Paused: {player.Paused}"); // False // Must call Play() again to restart await player.Play("/tmp/audio/music.wav"); ``` ``` -------------------------------- ### Player.Pause() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Pauses the current audio playback without discarding buffered data. The `Paused` property is set to true, while the `Playing` property remains unchanged. This operation is platform-dependent. ```APIDOC ## Player.Pause() — Pause Playback Pauses ongoing playback without clearing the buffer. Sets `Paused = true`; does not modify `Playing`. On Unix systems, the underlying process is suspended using `kill -STOP`. On Windows, the MCI `Pause` command is issued and the playback timer is stopped to track remaining duration. ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); await Task.Delay(3000); // listen for 3 seconds await player.Pause(); Console.WriteLine($"Playing: {player.Playing}"); // True Console.WriteLine($"Paused: {player.Paused}"); // True ``` ``` -------------------------------- ### Recorder.Stop() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Stops the active recording session, flushes the audio data to the specified file, and sets the `Recording` status to false. Fires the `RecordingFinished` event. ```APIDOC ## Recorder.Stop() ### Description Stops the active recording session and flushes the audio data to the file specified in the preceding `Record()` call. Sets `Recording = false` and fires `RecordingFinished`. Has no effect if no recording is in progress. ### Method ```csharp await recorder.Stop(); ``` ### Usage Example ```csharp using NetCoreAudio; var recorder = new Recorder(); recorder.RecordingFinished += (sender, args) => Console.WriteLine("File saved successfully."); await recorder.Record("/tmp/output.wav"); await Task.Delay(10000); // record for 10 seconds await recorder.Stop(); // Output: "File saved successfully." Console.WriteLine($"Recording: {recorder.Recording}"); // False ``` ``` -------------------------------- ### Handle Playback Completion with Player.PlaybackFinished Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt An event that fires when audio playback finishes naturally. Use it to trigger subsequent actions like playing the next track in a playlist. ```csharp using NetCoreAudio; var player = new Player(); var playlist = new Queue(new[] { "/tmp/audio/track1.wav", "/tmp/audio/track2.wav", "/tmp/audio/track3.wav" }); player.PlaybackFinished += async (sender, args) => { Console.WriteLine("Track finished."); if (playlist.TryDequeue(out var nextTrack)) { Console.WriteLine($"Playing next: {nextTrack}"); await player.Play(nextTrack); } else { Console.WriteLine("Playlist complete."); } }; // Start the first track if (playlist.TryDequeue(out var firstTrack)) await player.Play(firstTrack); ``` -------------------------------- ### Stop Playback with Player.Stop() Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt Stops audio playback and clears the buffer. Playback must be restarted with Play(). Cleans up temporary MCI files on Windows. ```csharp using NetCoreAudio; var player = new Player(); await player.Play("/tmp/audio/music.wav"); await Task.Delay(5000); await player.Stop(); Console.WriteLine($"Playing: {player.Playing}"); // False Console.WriteLine($"Paused: {player.Paused}"); // False // Must call Play() again to restart await player.Play("/tmp/audio/music.wav"); ``` -------------------------------- ### Player.PlaybackFinished Event Source: https://context7.com/mobiletechtracker/netcoreaudio/llms.txt An event that fires when audio playback completes naturally. This can be used to trigger subsequent actions, such as playing the next track in a queue. ```APIDOC ## Player.PlaybackFinished ### Description An `EventHandler` that fires when a track finishes playing naturally (not when stopped manually). Internally sets `Playing = false`. Multiple handlers can be attached to trigger follow-up logic such as queuing the next track. ### Event Signature ```csharp public event EventHandler PlaybackFinished; ``` ### Usage Example ```csharp using NetCoreAudio; var player = new Player(); var playlist = new Queue(new[] { "/tmp/audio/track1.wav", "/tmp/audio/track2.wav", "/tmp/audio/track3.wav" }); player.PlaybackFinished += async (sender, args) => { Console.WriteLine("Track finished."); if (playlist.TryDequeue(out var nextTrack)) { Console.WriteLine($"Playing next: {nextTrack}"); await player.Play(nextTrack); } else { Console.WriteLine("Playlist complete."); } }; // Start the first track if (playlist.TryDequeue(out var firstTrack)) await player.Play(firstTrack); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.