问题描述
因此,我正在使用Xamarin表单在Visual Studio中开发适用于Android和iOS的应用程序,我需要一个按钮来播放声音,但是当我按下按钮时,我遇到了一个问题:“ system.argumentnullexception已被引发”,而我没有“流”值,但我真的看不到缺少的地方。 这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace PrototypeII
{
public partial class MainPage : ContentPage
{
Button panic;
Button settings;
Button relax;
public MainPage()
{
InitializeComponent();
BackgroundColor = Color.LightGray;
panic = new Button
{
Margin = new Thickness(10),FontSize = 30,BackgroundColor = Color.Red,Text = "Panic",TextColor = Color.Black,};
panic.Clicked += panic_clicked;
relax = new Button
{
Margin = new Thickness(10),BackgroundColor = Color.GreenYellow,Text = "Tchill",};
settings = new Button
{
Margin = new Thickness(10),FontSize = 20,Text = "..."
};
var Grid = new Grid
{
Margin = new Thickness(20,40),ColumnDeFinitions =
{
new ColumnDeFinition { Width = new GridLength(1,GridUnitType.Star) },new ColumnDeFinition { Width = new GridLength(1,},RowDeFinitions =
{
new RowDeFinition { Height = new GridLength(0.5,GridUnitType.Star)},new RowDeFinition { Height = new GridLength(1,}
};
Grid.Children.Add(settings,3,0);
Grid.Children.Add(panic,1);
Grid.SetColumnSpan(panic,2);
Grid.Children.Add(relax,2,2);
Grid.SetColumnSpan(relax,2);
Content = Grid;
}
private void panic_clicked(object sender,EventArgs e)
{
var assembly = typeof(App).GetTypeInfo().Assembly;
Stream audioStream = assembly.GetManifestResourceStream("PrototypeII.123.mp3");
var audio = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
audio.Load(audioStream);
audio.Play();
}
}
}
如果您能告诉我如何解决此问题,或者...一种更简单的方法,请告诉我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)