Play Midi
Play Midi
Play Midi
Play Midi
Play Midi
Play Midi Play Midi Play Midi Play Midi Play Midi Play Midi Play Midi Play Midi
Play Midi Play Midi
Play Midi
Go Back  Xtreme Visual Basic Talk > > > Play Midi


Reply
 
Thread Tools Display Modes
  #1  
Old 10-04-2005, 06:31 AM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default Play Midi


I have the following code but it doesn't play the midi, can anyone help please ???


Code:
Public Class Form1
    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
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



        'Load file into mciSendString.
        mciSendString("OPEN" & Application.StartupPath & "\theworl.mid" & "TYPE SEQUENCER ALIAS theworld", String.Empty, 0, 0)
        'Play file.
        mciSendString("PLAY theworld", String.Empty, 0, 0)
    End Sub

End Class

The original code is:

Code:
'Load file into mciSendString.
mciSendString("OPEN C:\theworld.mid TYPE SEQUENCER ALIAS makeoneup", String.Empty, 0, 0)

'Play file.
mciSendString("PLAY makeoneup", String.Empty, 0, 0)

But now i want it to automaticly point to the application folder which can offcourse be different depending where people install it.
Reply With Quote
  #2  
Old 10-04-2005, 07:17 AM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

mciSendString does not support long filenames.

I think you'll have to call GetShortPathName API to condense the long Application.StartupPath filename
from like
"C:\Documents And Settings\Some User\My Documents\Visual Studio Projects\My Project\bin"
to
"C:\Docume~1\SomeUs~1\MyDocu~1\Visual~3\MyProj~2\bin"
So that there are no spaces (these are what trip mciSendString up, because spaces typically denote that a new keyword is coming up next.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 10-04-2005, 07:42 AM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Quote:
Originally Posted by Iceplug
mciSendString does not support long filenames.

I think you'll have to call GetShortPathName API to condense the long Application.StartupPath filename
from like
"C:\Documents And Settings\Some User\My Documents\Visual Studio Projects\My Project\bin"
to
"C:\Docume~1\SomeUs~1\MyDocu~1\Visual~3\MyProj~2\bin"
So that there are no spaces (these are what trip mciSendString up, because spaces typically denote that a new keyword is coming up next.
Ok i included

Code:
     Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
But it still wil not start, i left the rest of the code as it was, am i missing something ???
Reply With Quote
  #4  
Old 10-04-2005, 03:38 PM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You have to actually convert Application.StartupPath to a short path name! The declaration itself isn't going to actively sniff out long path names in the project and convert them all.

Dim SPN As String

GetShortPathName(Application.StartuPath, SPN, 255)
Application.StartupPath goes in as the long path name
SPN comes out as the Short Path Name...
and 255 is how long the path name can be.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 10-04-2005, 04:22 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

gonna try that tomorrow, thanks for the advice and help iceplug
Reply With Quote
  #6  
Old 10-04-2005, 05:33 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

I tried what you said but i get the following error with that

Warning 1 Variable 'SPN' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.

Stating to the SPN in here GetShortPathName(Application.StartuPath, SPN, 255)
Reply With Quote
  #7  
Old 10-04-2005, 06:39 PM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

But does it run?
If it worries you so much, then set it to String.Empty .
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #8  
Old 10-04-2005, 06:50 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Nope it did not run either
Reply With Quote
  #9  
Old 10-04-2005, 06:52 PM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

So... what's the problem? Did nothing come out of the function? Or was it actually an error that prevented the program from running.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #10  
Old 10-04-2005, 06:53 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Oh and what do you mean string empty ?? you mean like this ??

Dim SPN As String ""
Reply With Quote
  #11  
Old 10-04-2005, 06:53 PM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

String.Empty, as in
Dim SPN As String
SPN = String.Empty
yes, rougly equivalent to SPN = ""
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #12  
Old 10-04-2005, 06:54 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

this error stopped it from working

Warning 1 Variable 'SPN' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.

liek described earlier post
Reply With Quote
  #13  
Old 10-04-2005, 06:57 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Ok i tried it with the empty string then i get this error

A call to PInvoke function 'test!WindowsApplication1.Form1::GetShortPathName' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Reply With Quote
  #14  
Old 10-04-2005, 07:03 PM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

According to the example, you need to fill SPN with some pads.
SPN = "".PadRight(" ", 256)
Maybe that will work.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #15  
Old 10-04-2005, 07:49 PM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

strange cause now it tells me to convert your code to

SPN = "".PadRight(" ", CChar(CStr(256)))

then it doesn't work again

get the following error

Conversion from string " " to type 'Integer' is not valid.
Reply With Quote
  #16  
Old 10-04-2005, 08:18 PM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Oh, well, look at the arguments instead of pasting... it should be
SPN = "".PadRight(256, " ")
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #17  
Old 10-05-2005, 04:45 AM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Still no luck with it, im gonna give up with this i gues but thanks for all the help anyway.
Reply With Quote
  #18  
Old 10-05-2005, 07:22 AM
Iceplug's Avatar
IceplugPlay Midi Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

OK, I forgot you have to kill the null character at the end of the string as well.
Code:
Dim StrEndLoc As Integer = SPN.IndexOf(Convert.ToChar(0)) SPN = SPN.Substring(0, StrEndLoc)
Also, you might want to check the first call to mciSendString.
Code:
mciSendString("OPENspace" & Application.StartupPath & "\theworl.mid" & "spaceTYPE SEQUENCER ALIAS theworld", String.Empty, 0, 0)
Your terms are bundled together and you need spaces in between them.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #19  
Old 10-05-2005, 11:25 AM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Object reference not set to an instance of an object.

that is what i get for the following line

Dim StrEndLoc As Integer = SPN.IndexOf(Convert.ToChar(0))
Reply With Quote
  #20  
Old 10-05-2005, 11:28 AM
cyberops cyberops is offline
Centurion
 
Join Date: Apr 2005
Posts: 192
Default

Ok i fixed the one above now i have the following error directed towards the line i have in blue, see the entire code how i have it now.

Length cannot be less than zero.
Parameter name: length


Code:
 Public Class Form1
    Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    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


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim SPN As String
        SPN = "".PadRight(256, " ")
        Dim StrEndLoc As Integer = SPN.IndexOf(Convert.ToChar(0))
        SPN = SPN.Substring(0, StrEndLoc)






        mciSendString("OPENspace" & Application.StartupPath & "\theworld" & "spaceTYPE SEQUENCER ALIAS theworld", String.Empty, 0, 0)

        'Play file.
        mciSendString("PLAY theworld", String.Empty, 0, 0)

    End Sub
End Class
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Play Midi
Play Midi
Play Midi Play Midi
Play Midi
Play Midi
Play Midi Play Midi Play Midi Play Midi Play Midi Play Midi Play Midi
Play Midi
Play Midi
 
Play Midi
Play Midi
 
-->