如何从Silverlight中的FileReference加载MP3文件? 我在Silverlight中寻找这个

有帮助吗?

解决方案

这很容易做到。

这是一个快速示例。 XAML:

<StackPanel>
    <MediaElement x:Name="media" />
    <Button Content="Load MP3" Width="200" Click="Button_Click" />
</StackPanel>

和c#:

private void Button_Click(object sender, RoutedEventArgs e)
{
    // Create an instance of the open file dialog box.
    OpenFileDialog openFileDialog1 = new OpenFileDialog();

    // Set filter options and filter index.
    openFileDialog1.Filter = "MP3 Files (.mp3)|*.mp3";
    openFileDialog1.FilterIndex = 1;

    openFileDialog1.Multiselect = false;

    // Call the ShowDialog method to show the dialog box.
    bool? userClickedOK = openFileDialog1.ShowDialog();

    // Process input if the user clicked OK.
    if (userClickedOK == true)
    {
        // Open the selected file to read.
        System.IO.Stream fileStream = openFileDialog1.File.OpenRead();

        media.SetSource(fileStream);
        media.Play();
    }

}

我会让你添加有关加载等文本的输出面板。 :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top