RayT
asked on
How Do I Play An Audio File
How do I play an audio file (mp3, wav, etc.) within a Visual Studio Professional 2019 application? I want play the audio file asynchronously. Please provide an example. Thanks.
ASKER
Thanks. But this only plays wav files.
Noted. Can i know what is the audio format that you're looking forward?
ASKER
Any format. mp3, wav, m4a
I've done it with Windows Media Player. I was curious if other ways existed.
I've done it with Windows Media Player. I was curious if other ways existed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! That's exactly what I need!
Step 1: Create a new windows application. Open Visual Studio > File > New > Project > Windows Application > Rename it to ‘WindowsPlayAudio’.
Step 2: Drag and drop a label, 2 button controls and an OpenFileDialog component to the form. Rename them as follows :
Label1 – lblFile
Button1 – btnOpen
Button2 – btnPlay
TextBox – txtFileNm
OpenFileDialog – Set the Filter to ‘WAV Files|*.wav’
Step 3: On the ‘btnOpen’ click, display File Open dialog box and accept the selected .wav file in the txtFileNm textbox
Step 4: Code the btnPlay click event to play the selected file asynchronously
Step 5: That’s it. Run the application (F5). Click the Select File button and choose a .wav file. Click on the play button to play the file asynchronously.
Code:
Open in new window
More information:
https://www.dotnetcurry.com/ShowArticle.aspx?ID=115