how do I write a simple code in C# that plays a mp3 file when i click a button.
If you System.Diagnostics.Process.Start the mp3 file by name, I would expect any associated player application - such as media player - to launch and play the file. Are you asking how to play an MP3 file without displaying a player?
You can use the Windows Media Player ActiveX control just fine.
Related
I am writing a desktop C# app to manage my MP3 library (it's essentially a bulk MP3 tag editor) and I want to be able to play songs while working on the library.
I do not want to embed a music player into my app and I am happy with whatever my system has configured to play music (in my case I have Groove Music set as a default player on Windows 10).
Launching a song is easy: simply call Process.Start(songPath);. The trouble is that Groove Music steals focus which is annoying because it breaks my work flow.
How can I launch an external music player so that it plays in the background and doesn't steal focus?
I have tried https://stackoverflow.com/a/19049930/497403 with the following command lines:
cmd.exe songPath
"c:\Program Files (x86)\Windows Media Player\wmplayer.exe" songPath
However, in both cases the music player window (Grove in the first case, Media Player in the second) still comes into foreground and steals focus.
I suppose I could, as a workaround, just embed Windows Media Player ActiveX in my app, but I'm still curious why I cannot get WMPlayer to start without grabbing focus, with SW_SHOWNOACTIVATE/SW_SHOWMINNOACTIVE and what-not.
I want to play .wav sound in my application. I know how to do it. For example with a SoundPlayer class:
SoundPlayer player = new SoundPlayer();
player.SoundLocation = #"C:\path\sample.wav";
player.Load();
player.Play();
At home I have multiple Applications which can play sounds. However at job, I can't do it. Normally the computer can make sounds (youtube, Windows Media Player, etc.).
I investigated that my application does not appear in Volume Mixer.
In the end it was faulty wav file. I converted it to mp3 and then back to wav and now it works.
I used:
System.Diagnostics.Process.Start(#"D:\Song1.mp3");
It played the MP3 file with my default Media Play (e.g Window Media Player);
I have another MP3 File (e.g D:\Song2.mp3) that i want to append/queue to the current Media Player. Anyone please tell me how to do this?
Have you taken a look at Windows Media Player SDK. Once setup you will be able queue/append media file programically.
I want to use a media player in C# that reads these extensions : wmv,api,flv,mp3,mp4 and swf..
I tried Silverlight media player but its working with wmv and mp3 only.. and the same with the mediaElement in silverlight.. And FlowPLayer will only play flv, mp4 and mp3.
Has anyone any suggestion ?
Thanks alot !!
Why don't you use VLC media Player ActiveX ,here is a Project that helps you to integrate http://vlcdotnet.codeplex.com/
since LongTail (aka JWplayer) can play flv files i converted all my files to flv and played them with LongTail
I want in the win Application (written in C#), the sound (Wav Format) play as Background Sound, and mouse over Control play small wav sound File,
and when Click on Button, Stop Background Sound and ... .
Thanks For your guidance.
You could try look around in the System.Media namespace. There is a SoundPlayer which is able to play Wave files.
To play a wav file in a loop, you can use the following code:
string filename = #"C:\WINDOWS\Media\notify.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(filename);
player.PlayLooping();
To stop playing, you simple call Stop():
player.Stop();
Play around a bit, there's more if you need it.
you can use Windows Media Player:
reference C:\Windows\System32\wmp.dll in your project
to launch a wav file:
WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayerClass();
wmp.URL = "[wav file path]";
//then control the player with :
wmp.controls.play(), stop(), ...
for the second wav file, do the same thing with another instance of WindowsMediaPlayer etc...
you can also use Managed DirectX : Managed DirectX Tutorial Part 2
Did you try to play each of them in a separate thread ?