无法弄清楚 SimpleAudioPlayer.CrossSimpleAudioPlayer,很可能找不到文件 (System.Reflection.TargetInvocationExceptio)

Can't figure out SimpleAudioPlayer.CrossSimpleAudioPlayer, it most likely cannot find the file (System.Reflection.TargetInvocationExceptio)

我尝试的实现

      using INWORK.Models;
using INWORK.Services;
using INWORK.Views;
using MvvmHelpers;
using Plugin.SimpleAudioPlayer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace INWORK.ViewModels
{
    public class AboutViewModel : ViewModelBase, INotifyPropertyChanged
    {
        public AboutViewModel()
        {
            //MessagingCenter.Subscribe<ViewModelBase>
            Task.Run(async () => await Refresh());
            Title = "About";
            OpenWebCommand = new Command(async () => await Browser.OpenAsync("https://aka.ms/xamarin-quickstart"));
            var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;

            player.Load(GetStreamFromFile("SmallBeep.wav"));
            player.Play();
        }

        public ICommand GoInfoCommand { get; set; }

        private Stream GetStreamFromFile(string filename)
        {
            var assembly = typeof(App).GetTypeInfo().Assembly;
            var stream = assembly.GetManifestResourceStream("ĪNWORK." + filename);
            return stream;
        }

        public async Task Refresh()
        {
            Device.StartTimer(TimeSpan.FromSeconds(0.5), () =>
            {
                if (StaticClass.refreshbool == true)
                {
                    StaticClass.refreshbool = false;

                    Loadup();
                    StaticClass.passedbool = true;
                }

                return true;
            });
        }

        public ICommand OpenWebCommand { get; }
    }
}

更多文本的上下文 我试图将文件作为 AndroidResource 和 Embedded 资源添加到 android 解决方案(在可绘制对象和资产中) 以及主资产文件夹中的嵌入式资源(我不知道资产文件夹是否需要在某处声明),但到目前为止所有尝试都导致了相同的错误


System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

我有点像个白痴,但以防万一有人对此有疑问

放在主文件夹中 embeddedresource:

var stream = assembly.GetManifestResourceStream("INWORK.Assets." + filename);

整个路径需要用点定义,然后一切正常

如果您只想将它​​用于 Android,您可以将它作为 AndroidAsset 放在 Android 项目的资产文件夹中,而不是 AndroidResource 就像你一样。然后播放:

Plugin.SimpleAudioPlayer.ISimpleAudioPlayer player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
_ = player.Load("beep.wav");
player.Play();