其他分享
首页 > 其他分享> > 如何使用MediaElement播放本地mp3文件

如何使用MediaElement播放本地mp3文件

作者:互联网

我正在使用Silverlight 4(C#)创建一个简单的媒体播放器.现在我正在使用MediaElement但它给我一个错误

error 4001: …. System.Collections.ListDictionaryInternal

现在,当我要设置MediaElement的源时,会发生此错误.因此,当用户点击“播放”时,它将设置第一首歌曲的来源.

Song s = afspeelijst.ElementAt(currentPlayingIndex);
media.Source = new System.Uri(s.FilePath);
media.Position = TimeSpan.Zero;
media.Play();

下一个代码也不起作用,但是它消除了错误.但仍然没有声音:s

media.SetSource(new FileStream(s.FilePath, FileMode.Open));

解决方法:

您可能想签出此代码.它对我来说很好:)

mediaElement1.LoadedBehavior = MediaState.Manual;
mediaElement1.Source = new Uri(@"D:/ExamplePath/myVideoFile.avi");
//@ means that the string behind is a path so / won't be 
//treated like a special character
mediaElement1.Play();

标签:c,silverlight
来源: https://codeday.me/bug/20191208/2094977.html