Вопрос

Как загрузить файлы MP3 из FileReference в Silverlight? Я ищу что-то вроде этого в 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