Click here to Skip to main content
15,895,557 members
Articles / Programming Languages / Visual Basic

Fun with Sound

Rate me:
Please Sign up or sign in to vote.
4.92/5 (25 votes)
10 Jul 2014CPOL5 min read 42.3K   2.2K   53  
Playing your favorite music and sound files all at once
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace MCIDEMO
	Public Partial Class Form2
		Inherits Form

		' Declare the nofify constant
		Public Const MM_MCINOTIFY As Integer = 953
		Public Const MCI_NOTIFY_SUCCESSFUL As Integer = 1
		Public Const NOTIFY_ABORTED As Integer = 4

		Public parent As Form
		Protected Overrides Sub WndProc(ByRef m As Message)
			If m.Msg = MM_MCINOTIFY Then
				' The file is done playing, do whatever
				System.Diagnostics.Debug.WriteLine(m.ToString())


				For Each itm As Form1.ListItem In DirectCast(Me.parent, Form1).listBox1.Items
					If itm.DeviceId = CInt(m.LParam) Then
						'To handle wav file play looping      
						If (itm.Filename.Substring(itm.Filename.Length - 4).ToUpper() = ".WAV") AndAlso (CInt(m.WParam) = MCI_NOTIFY_SUCCESSFUL) AndAlso (itm.Playlooping) Then
							Dim p As New MciPlayer()
							p.[Alias] = itm.[Alias]
							p.Isloaded = True
							p.PlayFromStart(Me.Handle)

							Exit For
						Else
							listBox1.Items.Add(DateTime.Now.ToString() & " " & DirectCast(itm.Filename, String))
							Exit For

						End If
					End If


				Next
			End If

			MyBase.WndProc(m)
		End Sub


		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub listBox1_SelectedIndexChanged(sender As Object, e As EventArgs)

		End Sub
	End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Singapore Singapore
Coder. Hacker. Fixer.

Comments and Discussions