我使用此代码播放单个mp3音频文件,并使用MediaElement:
Uri Path = new Uri("AudioFiles/music.mp3", UriKind.Relative);
SoundPlayer.Source = Path;
SoundPlayer.Play();
但我得到了这个错误:
mscorlib.ni.dll中发生类型'System.ArgumentException'的异常,但未在用户代码中处理
附加信息:无法将给定的System.Uri转换为Windows.Foundation.Uri。
那有什么问题呢?
谢谢
根据文件的位置,您可能需要不同的Uri方案。尝试:
SoundPlayer.Source = new Uri(@"ms-appdata:///local/AudioFiles/music.mp3"); // if your file is in IsolatedStorage
SoundPlayer.Source = new Uri(@"ms-appx:///AudioFiles/music.mp3"); // if your file is a Build-in content
另请注意,SoundPlayer.Play()
如果ifSoundPlayer.Autoplay
设置为true(默认设置),则不需要。万一它是假的-您将不得不开始手动播放,MediaOpened
以防万一Source
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句