开发者

How to load MP3 files from a FileReference in Silverlight?

How to load MP3 files from a FileReference in Silverlight? I'm looking for s开发者_JAVA百科omething like this in Silverlight


This is fairly easy to do.

Here is a quick sample. Xaml:

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

And the 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();
    }

}

I'll let you add the output panel with the text about loading and such. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜