كيفية تحميل ملفات MP3 من FileReference في Silverlight؟
-
06-07-2019 - |
سؤال
كيفية تحميل ملفات MP3 من FileReference في Silverlight؟ أنا أبحث عن شيء مثل هذا في Silverlight
المحلول
وهذا هو السهل القيام به.
وهنا عينة سريعة. XAML:
<StackPanel>
<MediaElement x:Name="media" />
<Button Content="Load MP3" Width="200" Click="Button_Click" />
</StackPanel>
وج #:
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();
}
}
وسوف تتيح لك إضافة لوحة الإخراج مع النص حول تحميل ومثل هذا. :)
لا تنتمي إلى StackOverflow