https://www.bilibili.com/video/BV1fP4y1o7qS/
https://github.com/search?q=Plugin.Maui.Audio&type=repositories
https://github.com/jfversluis/MauiPluginAudioSample/blob/main/MauiPluginAudioSample/MainPage.xaml.cs
音频录制
https://github.com/math3ussdl/Plugin.Maui.AudioRecorder
Plugin.Maui.Audio
https://github.com/jfversluis/Plugin.Maui.Audio/issues/40
在Maui项目中添加Plugin.Maui.Audio NuGet包。
在应用程序的Startup.cs文件中注册AudioService服务,并将其添加到应用程序的IServiceCollection中。示例代码如下:
using Plugin.Maui.Audio;
...
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAudio();
...
}
在需要使用音频功能的页面或控件中,注入IAudioPlayer或IAudioRecorder服务,并使用它们来播放或录制音频。示例代码如下:
using Plugin.Maui.Audio;
...
public partial class MyPage : ContentPage
{
private readonly IAudioPlayer _audioPlayer;
private readonly IAudioRecorder _audioRecorder;
...
public MyPage(IAudioPlayer audioPlayer, IAudioRecorder audioRecorder)
{
InitializeComponent();
...
_audioPlayer = audioPlayer;
_audioRecorder = audioRecorder;
}
...
private async void PlayButton_Clicked(object sender, EventArgs e)
{
await _audioPlayer.PlayAsync("my_audio.mp3");
}
...
private async void RecordButton_Clicked(object sender, EventArgs e)
{
await _audioRecorder.RecordAsync("my_audio.wav");
}
...
}
以上就是使用Plugin.Maui.Audio插件的基本步骤。您可以根据自己的需求进一步了解和使用该插件的其他功能。
var player = _audioManager.CreatePlayer(await FileSystem.OpenAppPackageFileAsync("demo.wav"));
player.Volume = 111;
//player.Duration = 1;
//player.CurrentPosition = 1;
//player.IsPlaying;
player.Balance = 1;
player.Pause();
player.Stop();
player.Dispose();
player.Speed = 1;
player.Play();
// _audioManager.p
//_audioPlayer.Play();
// _audioRecorder.StartRecordAsync(CultureInfo.CurrentCulture, IProgress<string>, CancellationToken.None);
文档更新时间: 2023-11-16 21:09 作者:admin