2012-08-05 58 views
0

我需要在我的metro应用程序中为Windows 8设置mediaElement控件的源!如何在metro app c#中设置mediaElement的源?

这里是我的代码:

string requestUrl = "ms-appx://ArcadiaDJ/Musique/test.mp3"); 
mediaElement_SoundEffect.Source = new Uri(requestUrl); 
mediaElement_SoundEffect.play();      

我可以设置信号源,但不MediaElement的工作玩。没有音乐

我发现这个解决办法,但我需要加载设置源页面动态

var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); 

openPicker.SuggestedStartLocation =Windows.Storage.Pickers.PickerLocationId.MusicLibrary; 

openPicker.FileTypeFilter.Add(".mp3"); 
openPicker.FileTypeFilter.Add(".wav"); 
file = await openPicker.PickSingleFileAsync(); 

mediaControl.SetSource(stream, file.ContentType); 

谢谢

+0

可能重复的[无法在Windows 8中播放声音](http://stackoverflow.com/questions/10984038/unable-to-play-sound-in-windows-8) – 2014-01-14 12:41:04

回答

1

有一些关于你的代码奇怪的事情。您在名为mediaElement_SoundEffect的对象上设置Source属性,然后在名为mediaElement的对象上调用.Play方法。所以你应该修正你的代码或者修改你的例子,以便更准确地了解你在做什么。

也检出this answer我写了一段时间回来......你应该添加mediaElement到Visual Tree。

+0

对不起,我纠正。和thansk的链接 – 2012-08-05 18:24:45

相关问题