Page 1 of 1

2 trong 1: Play a Wav, Play a mid

Posted: Tue 13/05/2008 3:49 pm
by truongphu
Thủ thuật: 2 trong 1: Play a Wav, Play a mid
Tác giả: Patrick Gillespie, truongphu edit
Mô tả: Chỉ vài dòng code có thể play a mid hay a wav


Code: Select all

  1. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
  2. Dim ret As Long  'Code by Patrick Gillespie
  3. Private Sub Command1_Click()  ' Open a midi file
  4. ret = mciSendString("open C:\Dancing_Queen.Mid type sequencer", 0&, 0, 0)
  5. End Sub
  6. Private Sub Command2_Click()  ' Play a midi file
  7. ret = mciSendString("play C:\Dancing_Queen.Mid", 0&, 0, 0)
  8. End Sub
  9. Private Sub Command3_Click()  ' Stop a midi file
  10. ret = mciSendString("stop C:\Dancing_Queen.Mid", 0&, 0, 0)
  11. End Sub
  12. Private Sub Command4_Click()  ' Pause a midi file
  13. ret = mciSendString("pause C:\Dancing_Queen.Mid", 0&, 0, 0)
  14. End Sub
  15. Private Sub Command5_Click()  ' Resume playing a midi file
  16. ret = mciSendString("resume C:\Dancing_Queen.Mid", 0&, 0, 0)
  17. End Sub
  18. Private Sub Command6_Click()  ' Play a Wav
  19. ret = mciSendString("open C:\parent-teachernite.wav type waveaudio alias theFile", 0&, 0, 0)
  20. End Sub
  21. Private Sub Command7_Click()  ' Close Form
  22. ret = mciSendString("close C:\Dancing_Queen.Mid", 0&, 0, 0)
  23. End
  24. End Sub

Ghi chú: chưa test nhiều, nhờ các bạn

Chạy một tệp nhạc không sử dụng OCX

Posted: Sat 21/08/2010 3:24 pm
by VuVanHoanh
  1. Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  2. Private Const SND_ASYNC                         As Long = &H1
  3. Private Const SND_NODEFAULT                     As Long = &H2
  4.  
  5. Public Function PlaySnd(ByVal sFile As String) As String
  6.     sndPlaySound sFile, SND_ASYNC Or SND_NODEFAULT
  7. End Function