Play MIDI File?
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
I know I can use My.Computer.Audio.Play() to play a wav audio file, but that doesn't work with MIDI files. Is there a way I can play a MIDI file (or any other audio file) without using the WindowsMediaPlayer control, and without extracting the resource from the exe?
Thanks!
Thanks!
i found this module
Code: Select all
i dont know how it works maybe you can give a tryPublic Module Sounds
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Function PlayMidiFile(ByVal MidiFile As String) As Boolean
'MidiFile = File's Full Path
'Returns: True if successful, false otherwise
Dim lRet As Long
On Error Resume Next
If Dir(MidiFile) = "" Then Exit Function
lRet = mciSendString("open sequencer!" & MidiFile & " alias midi", "", 0, 0)
lRet = mciSendString("play midi from 0", 0&, 0, 0)
End Function
Public Function StopMidi() As Boolean
'Stops midi from playing
'Returns: True if successful, false otherwise
Dim lRet As Long
On Error Resume Next
'Stop any currently playing .midi
lRet = mciSendString("stop midi", "", 0, 0)
StopMidi = (lRet = 0)
lRet = mciSendString("close midi", "", 0, 0)
End Function
Public Function killMidi() As Boolean
'Stops midi from playing
'Returns: True if successful, false otherwise
Dim lRet As Long
On Error Resume Next
'Stop any currently playing .midi
lRet = mciSendString("stop midi", "", 0, 0)
End Function
Public Function ContinueMidiFile(ByVal MidiFile As String) As Boolean
'MidiFile = File's Full Path
'Returns: True if successful, false otherwise
Dim lRet As Long
On Error Resume Next
If Dir(MidiFile) = "" Then Exit Function
lRet = mciSendString("open sequencer!" & MidiFile & " alias midi", "", 0, 0)
lRet = mciSendString("play midi", 0&, 0, 0)
End Function
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
End Module
Find my programs on Softpedia
I'll give that a try.
Also, just a random question, what's the difference between a module and a class?
Also, just a random question, what's the difference between a module and a class?
Cheatmasterbw wrote:I'll give that a try.Both classes and modules are reference types that encapsulate the items defined within, but they differ in how items are accessed from other procedures.
Also, just a random question, what's the difference between a module and a class?
The main difference between classes and modules is that classes can be instantiated as objects while standard modules cannot. Because there is only one copy of a standard module's data, when one part of your program changes a public variable in a standard module, any other part of the program gets the same value if it then reads that variable. In contrast, object data exists separately for each instantiated object. Another difference is that unlike standard modules, classes can implement interfaces.
Classes and modules also use different scopes for their members. Members defined within a class are scoped within a specific instance of the class and exist only for the lifetime of the object. To access class members from outside a class, you must use fully qualified names in the format of Object.Member.
On the other hand, members declared within a module are publicly accessible by default, and can be accessed by any code that can access the module. This means that variables in a standard module are effectively global variables because they are visible from anywhere in your project, and they exist for the life of the program.
-msdn-
Find my programs on Softpedia
That makes sense.
I was able to simplify the code you posted:
I was able to simplify the code you posted:
Code: Select all
Thanks Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Sub PlayMidiFile(MidiFile As String)
On Error Resume Next
mciSendString("open sequencer!" & MidiFile & " alias midi", "", 0, 0)
mciSendString("play midi from 0", 0&, 0, 0)
End Sub
Public Sub StopMidi()
On Error Resume Next
mciSendString("stop midi", "", 0, 0)
mciSendString("close midi", "", 0, 0)
End Sub

5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023