WIP MP3-Player
The commented code doesn't work, but the currently uncommented code below does. I can open the dialog window, but after selecting the mp3-file, it doesn't play. The uncommented code does play the mp3-file.
Problem at "Öffnen der Datei" region.
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
namespace Music_Player
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public MediaPlayer mp = new MediaPlayer();
#region Öffnen der Datei
private void menuOffnen_Click(object sender, RoutedEventArgs e)
{
mp.Pause();
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = ".mp3";
dlg.Filter = "MP3 files (*.mp3)|*.mp3|M4A files (*.m4a)|*.m4a|All files (*.*)|*.*";
if (dlg.ShowDialog() == true)
{
mp.Open(new Uri(dlg.FileName));
labelsong.Content = dlg.SafeFileName;
}
//Offnen o = new Offnen();
//o.OffnenDerDatei();
mp.Play();
}
#endregion
#region ActionButtons
private void button_play_Click(object sender, RoutedEventArgs e)
{
mp.Play();
}
private void button_pause_Click(object sender, RoutedEventArgs e)
{
mp.Pause();
}
private void button_stop_Click(object sender, RoutedEventArgs e)
{
mp.Stop();
}
#endregion
private void slider_volume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
slidervolume.Maximum = 100;
slidervolume.Minimum = 0;
}
#region Beenden
private void menuBeenden_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
#endregion
}
}
Offnen.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;
using System.Windows.Media;
namespace Music_Player
{
class Offnen : MainWindow
{
public void OffnenDerDatei()
{
MediaPlayer mp = new MediaPlayer();
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = ".mp3";
dlg.Filter = "MP3 files (*.mp3)|*.mp3|M4A files (*.m4a)|*.m4a|All files (*.*)|*.*";
if (dlg.ShowDialog() == true)
{
mp.Open(new Uri(dlg.FileName));
labelsong.Content = dlg.SafeFileName;
}
}
}
}