Tag Archives: midi

Readymade Options for Playback of Music/Audio Files in VB and VB.NET – 1 of 2

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 3.90 out of 5)
 

This article and Part Two are to show some options available for Audio/Music playback if your not interested in making your own control or library. I do have an article on how to do basic music playback at this link with some quick and simple source code. But if you want more advanced features and don’t want to create the bulk of the playback code, then the content in these articles should help you out. This first article is on using some libraries I made around the MCISendString Windows API function and doesn’t have 3rd party dependency.

Note: You can now check out part two at this link on two 3rd party controls named Bass.dll and FMod.dll.


Visual Basic 6.0

For VB 6.0 is Music Module v2.2 that I made with Visual Basic 6.0 and contains the main features that a music player usually needs. It supports the most popular music formats like Wave, MIDI, and MP3 files. Some other features are calculating the MP3’s overall Bitrate, getting the Playing Position in various formats, Left/Right Volume Control with Muting, etc. While the class module is old, it still does the job well and does not rely on any 3rd Party .DLL’s or Resources. You can download the Class Module with Example at this link.

Visual Basic.NET 2002/2003

This option is basically for VB.NET 2002/2003 and would recommend you use it for those versions only. This library is called csMusicLibrary v1.0 Professional. This class contains more features than the VB 6 library.  The class has all of the features required for a normal music player and some extra features like basic playlist support, setting the music playback rate, setting the playing position and more. IF your interested in this option you can download the compiled class with example at this link.

Visual Basic 2005/2008/2010, and Higher

This next library definitely has the most features out of the options in this article. It is a major overhaul of the original csMusicLibrary. It is csMusicLibrary v3.1 – The Professional Series and made with Visual Basic 2005. It is completely XML commented with explanations about the Subs/Functions and Properties along with remarks. There are many options available and is easy to use and understand. Besides your normal playback features it can give your applications some basic recording capabilities, extract MP3 Tag v1.1 information, get the music playback status, and much more. Like the other options outlined above, this library does not rely on any 3rd party controls or resources. If you don’t need any super advanced features like visualizations, data manipulation, or sound effects, etc. then this library should work just fine for making a fully featured music application. You can download the compiled class with example at this link.


All these options should be fine for making a nice featured application. But you may be wanting more advanced features like FFT’s, Data Manipulation, Sound FX, and so on. That is where the next article will come in. Click this link to read part two about some third party controls. Have fun 🙂

Jason

Revised: 2014

Easily Play, Stop, Pause, and Resume MP3/Wav/WMA files in VB and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (31 votes, average: 3.42 out of 5)
 

This article will use the already established Windows API function MCISendString. The function is part of the Windows Multi-Media system in the winmm.dll using Multimedia Command Strings (MCI). WinMM is available on pretty much every modern Windows OS. Apart from having to install special codecs for uncommon audio/music formats, you can play many of the popular formats without any special setup or installation. If you want to know more about Multimedia Command strings you can check out a beginner tutorial I made at this link.

While the source code in this post is in VB.NET, you can simply change ‘as Integer‘ to ‘as Long‘. Otherwise the code should be fine.

Below is the API Function to get started.

'
'Api to send the commands to the mci device.
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal _
uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer

 

The next snippet is for the path to the file.

'The Chr(34) code is to put quotes at the beginning and end of the file's path.
'You can convert the long filename to the short filename and not need 'the quotes.
'That would just be more code that really isn't needed.
Dim fileToPlay As String

fileToPlay = Chr(34) & ("c:\MyFileToPlay.MP3") & Chr(34)

 

Below is a command sent to the MCI system to open and setup a new device to play the file that is specified in the fileToPlay variable.

'Let the command interface decide which device to use. Just specify the alias.
'The alias is the name you use to program that device. You can create multiple
'devices to play media at the same time and such with different alias's.
MCISendString "open " & fileToPlay & " alias myDevice", vbNullString, 0, 0

 

The device is now setup and you just need to execute the simple commands shown below.
Continue reading