Reputation: 502
I'm using mciSendString("play path repeat",0,0,0)
to play music in my project
and I'm using it specially for playing multiple sounds in the same time.
The problem is that I want to put the sounds in the executable path so I used a function to get the exe path
string ExePath() {
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
but mciSendString()
takes LPCSTR
so I tried the following
string music_cmd="play "+ExePath()+"\\war1.mp3 repeat";
mciSendString(music_cmd.c_str(),0,0,0);
The program runs without Errors but it doesn't play the sound. How can I fix this problem ?
Upvotes: 1
Views: 2402
Reputation: 17
the path should have no spaces, if you use a path like as
follows: C:\music\music 2.mp3
it will not work.
to make it work delete the space or create a new path without spaces like as follows: C:\music\music2.mp3
Other Observations: the path should have less than 255 characters, relative path will not work (it works when you compile, but when you run the program on another computer, it will not work), cannot have spaces, otherwise it will fail.
there is a workaround you can do which is simple, you will be able to play with dots and spaces on the path
mine is as follows:
path = Application.StartuPath & `\whateverMusic.mp3`
path = Chr(34) & path & Chr(34)
mciSendString("Open " & path & " alias " & oName, Nothing, 0, 0)
mciSendString("Play " & oName, Nothing, 0, 0)
Public Property Name As String
Set(value as String)
oName = value
End Set
Get
Return oName
End Get
End Property
From Here: https://www.youtube.com/watch?v=UWLTegpOuB0
Upvotes: 2