好吧,我創建了一個使用mciSendString的SOUND類。我正在使用它來播放我正在製作的RPG風格遊戲的音樂和其他聲音文件。它的工作原理,它運作良好......但。我的問題是,它需要聲音文件的完整路徑才能工作(不確定這是否爲真)。.net mcisendstring - 使用資源而不是完整路徑
下面是一些mcisendstring的querks的:
- mcisendstring恨空格,空格會造成死機(未能加載文件) - 添加引號路徑
- 點可以導致失敗加載(只點應該是爲了延伸)
- 非常長的路徑將導致加載失敗(允許的最大字符數爲255)
- 相對路徑將導致加載失敗...(不能使用類似chicken.mp3的東西...必須使用C:\ chicken.mp3) 個
- .wav文件將無法加載如果重複= TRUE
我嘗試添加文件到我的資源,並試圖路徑設置到資源,但它說:Value of type '1-dimensional array of Byte' cannot be converted to 'String'
。
任何幫助是極大的讚賞:)
這裏是我的代碼:
Public Class SOUND
Public 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
'Command String VERY IMPORTANT
Private oName As String = Nothing
Public Property Name As String
Set(value As String)
oName = value
End Set
Get
Return oName
End Get
End Property
Public Sub Play(ByVal id As Integer, ByVal repeat As Boolean, Optional volume As Integer = 1000)
If repeat = True Then
mciSendString("Open " & GetFile(id) & " alias " & oName, CStr(0), 0, 0) 'Open the file
mciSendString("play " & oName & " repeat ", CStr(0), 0, 0) 'then play with repeating value
Else
mciSendString("Open " & GetFile(id) & " alias " & oName, CStr(0), 0, 0)
mciSendString("play " & oName, CStr(0), 0, 0)
End If
'Optionally Set Volume
mciSendString("setaudio " & oName & " volume to " & volume, CStr(0), 0, 0)
End Sub
Public Sub Kill(ByVal song As String)
mciSendString("close " & song, CStr(0), 0, 0)
oName = Nothing
End Sub
' Media Library
Private Function GetFile(ByVal id As Integer) As String
Dim path As String = ""
'mcisendstring Hates spaces, spaces will cause crash (failure to load file) - ADD QUOTES
'Dots in path can cause failure to load (only dot should be for the extention)
'Very Long Paths will cause failure to load (Max Characters allowed is 255)
'Relative paths will cause failure to load...(cannot use something like chicken.mp3 ... must use ex:[C:\chicken.mp3])
'.wav files will fail to load if repeat = true
Select Case id
Case 0 'Game Over
path = "C:\FinalFantasy7-SendaDreamIntoTheUniverse.mp3"
Case 1 'Battle Sequence
path = "C:\FinalFantasyTactics-Garland_Magic.mp3"
Case 2 'Battle Victory
path = "C:\FinalFantasyLegend2-Victory.mp3"
Case 3 'Mission Time
path = "C:\FinalFantasyAdventure-Mission.mp3"
End Select
path = Chr(34) & path & Chr(34)
'Chr(34) is quotes...cannot just use "" because it will think that it is part of the string/path itself.
Return path
End Function
末級
我需要什麼:
- 我需要以某種方式獲得。 MP3文件作爲可用於路徑的資源,或者我需要一些其他方法,而不是將這些文件放在根驅動器或某些文件中其他完整的電腦路徑。
例東西我需要
變化
Select Case id
Case 0 'Game Over
path = "C:\FinalFantasy7-SendaDreamIntoTheUniverse.mp3"
End Select
到
Select Case id
Case 0 'Game Over
path = My.Resources.FinalFantasyAdventure_Mission
End Select
如何播放聲音:
(在另一個測試形式)
Dim intSound As Integer = 0
Dim snd As New SOUND 'SOUND is the sound class with mcisendstring
Private Sub PlaySoundBtn_Click(sender As System.Object, e As System.EventArgs) Handles PlaySoundBtn.Click
intSound += 1
With snd
.Name = "SOUND" & intSound 'SOUND is the alias along with the number (this one is SOUND1)
.Play(3, True, 500)
'3 is the song ID, True is for the repeat, 500 is for the optional volume (Max = 1000)
End With
End Sub
P.S.我在我的項目中使用XNA Graphics,我也有NuGet的BizArk Core。因此,如果我可以使用其中任何一種,請告訴我如何使用這兩種方法來做我需要做的事情。預先感謝您的幫助。
這是不可能與mciSendString。但當然可以使用XNA:http://msdn.microsoft.com/en-us/library/bb195053.aspx – 2012-03-14 16:46:45
好吧,我看了看頁面,但是,它並沒有幫助我什麼lol。我將如何去做這個.net(不是C#或C++) – 2012-03-14 17:18:00