我刚刚安装了一个软件包从nuget软件包管理简单音频播放器,我想播放一个声音或音频文件,但它不工作。在该项目的首选项中,我接受了r音频记录和sti;的权限;同样的问题是代码:
public MainPage()
{
InitializeComponent();
ISimpleAudioPlayer simpleAudioPlayer = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();;
Stream beepStream = GetType().Assembly.GetManifestResourceStream("App1.Beep.mp3");
ARandomMethod();
} private void ARandomMethod()
{
if(sth happens)
{
simpleAudioPlayer.Play();
}
}错误: 1)
Severity Code Description Project File Line Suppression State
Error NU1202 Package
Xam.Plugin.SimpleAudioPlayer.WPF 1.6.0 is not compatible with monoandroid13.0 (MonoAndroid,Version=v13.0). Package
Xam.Plugin.SimpleAudioPlayer.WPF 1.6.0 supports: net45
(.NETFramework,Version=v4.5) NewTimer.Android
C:\Users\PC\source\repos\NewTimer\NewTimer
\NewTimer.Android\NewTimer.Android.csproj 1
2)
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'simpleAudioPlayer' does not exist in the current context NewTimer C:\Users\PC\source\repos\NewTimer\NewTimer\NewTimer\MainPage.xaml.cs 86 Active如何解决这个问题,使用简单的音频播放器播放声音或音乐?
发布于 2022-11-27 13:33:14
这是一个基本的C#错误。您正在方法中声明一个局部变量,然后尝试在另一个方法中使用它。如果您想从多个方法引用一个对象,您必须在类级别的中声明它,以便它保持在作用域中。
// declare this at the class level so it remains in scope
ISimpleAudioPlayer simpleAudioPlayer
public MainPage()
{
InitializeComponent();
simpleAudioPlayer = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();;https://stackoverflow.com/questions/74590429
复制相似问题