0

我需要在我的 Metro 应用程序中为 Windows 8 设置 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);

谢谢

4

1 回答 1

1

您的代码有一些奇怪的地方。在名为 mediaElement_SoundEffect 的对象上设置 Source 属性,然后在名为 mediaElement 的对象上调用 .Play 方法。因此,您应该修复您的代码或修复您的示例以更准确地了解您正在做的事情。

另请查看我不久前写的这个答案……您应该将 mediaElement 添加到可视树中。

于 2012-08-05T17:37:08.447 回答