Frage

Wie MP3-Dateien von einem FileReference- in Silverlight laden? Ich bin auf der Suche nach so etwas wie dieser in Silverlight

War es hilfreich?

Lösung

Das ist ziemlich einfach zu tun.

Hier ist eine kurze Probe. XAML:

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

Und die 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();
    }

}

Ich lasse Sie das Ausgabefeld mit dem Text über das Laden und so hinzufügen. :)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top