Question

Well I am making a media player in the C# using the System.Media.SoundPlayer class but there are too many limitations in that like it only plays .wav files and there is no volume control in this and also there is no media-progessbar. So is there any better builtin class or custom class. if there is any please specify. Or even if there is any thing which will work parallel with it.

Was it helpful?

Solution

You can use the WPF MediaElement as full fledged audio and video player.

It is very easy to handle and brings more or less all functionality Windows Media Player has. If you use Windows Forms you can embedd the WPF control easily.

The only drawback in my optinion is that it needs Windows Media Player to be installed.

OTHER TIPS

You can use the Windows Media Player Control. An example is shown on MSDN.

private void PlayFile(String url)
{
    Player = new WMPLib.WindowsMediaPlayer();

    Player.URL = url;
    Player.controls.play();
}

If you want more control over playback, and don't want to tie yourself to WMP, you could look into using NAudio which is an open-source media library.

You need not worry about the file extensions if you use the MediaElement available in the toolbox.

Here's a snippet that can help you:

private void button4_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.AddExtension = true;
        ofd.DefaultExt = "*.*";
        ofd.Filter = "Media(*.*)|*.*";
        ofd.ShowDialog();
        mediaElement1.MediaOpened += new RoutedEventHandler(mediaElement1_MediaOpened);
        mediaElement1.Source = new Uri(ofd.FileName);
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {

        mediaElement1.Play();
    }

    private void button3_Click(object sender, RoutedEventArgs e)
    {
        mediaElement1.Stop();
    }

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        mediaElement1.Pause();

    }

For more details refer to: http://bitsandbinaries.wordpress.com/net-programming/wpfwindows-presentation-foundation/a-simple-media-player-program-in-c-net-4-0/

If you want more control, use NAudio (http://naudio.codeplex.com/) or SharpDX (http://sharpdx.org/). Using SharpDX I have built a media player that drives multiple sound cards (for different zones) with smooth fade-out for terminated song playback, ducking for announcements, etc..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top