471,594 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Need to know the VB code of how to stop Playing sound through a click button

Hi All;

Please, if any one knows the visual basic code, to be added to a Stop button in order to stop playing some sound of (*.Wav) type. I have achieved to find the code for start playing sound or music which is:

OLE.DoVerb (vbOLEPrimary)

But the one to stop or interupt the sound I could not find it.

Please let know

Thank you in advance

M C Benzerari
Aug 7 '07 #1
4 4842
Dököll
2,364 Expert 2GB
Hi All;

Please, if any one knows the visual basic code, to be added to a Stop button in order to stop playing some sound of (*.Wav) type. I have achieved to find the code for start playing sound or music which is:

OLE.DoVerb (vbOLEPrimary)

But the one to stop or interupt the sound I could not find it.

Please let know

Thank you in advance

M C Benzerari
Give this a whirl, Benzerari:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. Dim app_path As String
  4.  
  5.     app_path = App.Path
  6.     If Right$(app_path, 1) <> "\" Then app_path = app_path _
  7.         & "\"
  8.     txtFile.Text = app_path & "Alice_Cooper-Gimmie.mp3"
  9.  
  10.     ' Prepare the audio control.
  11.     mmcAudio.Notify = False
  12.     mmcAudio.Wait = True
  13.     mmcAudio.Shareable = False
  14.     mmcAudio.Command = "Close"
  15. End Sub
  16.  
  17. ' Play the MP3 file.
  18. Private Sub cmdPlay_Click()
  19.     If cmdPlay.Caption = "Play" Then
  20.         mmcAudio.FileName = txtFile.Text
  21.         mmcAudio.Command = "Open"
  22.         mmcAudio.Command = "Play"
  23.         cmdPlay.Caption = "Stop"
  24.     Else
  25.         mmcAudio.Command = "Stop"
  26.         mmcAudio.Command = "Close"
  27.     End If
  28. End Sub
  29.  
  30. Private Sub mmcAudio_StatusUpdate()
  31.     lblAudio.Caption = mmcAudio.Position & "/" & _
  32.         mmcAudio.Length
  33. End Sub
  34.  
  35. ' Prepare the control to play again.
  36. Private Sub mmcAudio_Done(NotifyCode As Integer)
  37.     mmcAudio.Command = "Close"
  38.     lblAudio.Caption = ""
  39.     cmdPlay.Caption = "Play"
  40. End Sub
  41.  
  42. Private Sub Form_Unload(Cancel As Integer)
  43.     ' Close the multimedia device.
  44.     mmcAudio.Command = "Close"
  45. End Sub
  46.  
  47.  
Hopefully this is what you wanted. Let us know if it works, just found this one...
Aug 8 '07 #2
Give this a whirl, Benzerari:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. Dim app_path As String
  4.  
  5.     app_path = App.Path
  6.     If Right$(app_path, 1) <> "\" Then app_path = app_path _
  7.         & "\"
  8.     txtFile.Text = app_path & "Alice_Cooper-Gimmie.mp3"
  9.  
  10.     ' Prepare the audio control.
  11.     mmcAudio.Notify = False
  12.     mmcAudio.Wait = True
  13.     mmcAudio.Shareable = False
  14.     mmcAudio.Command = "Close"
  15. End Sub
  16.  
  17. ' Play the MP3 file.
  18. Private Sub cmdPlay_Click()
  19.     If cmdPlay.Caption = "Play" Then
  20.         mmcAudio.FileName = txtFile.Text
  21.         mmcAudio.Command = "Open"
  22.         mmcAudio.Command = "Play"
  23.         cmdPlay.Caption = "Stop"
  24.     Else
  25.         mmcAudio.Command = "Stop"
  26.         mmcAudio.Command = "Close"
  27.     End If
  28. End Sub
  29.  
  30. Private Sub mmcAudio_StatusUpdate()
  31.     lblAudio.Caption = mmcAudio.Position & "/" & _
  32.         mmcAudio.Length
  33. End Sub
  34.  
  35. ' Prepare the control to play again.
  36. Private Sub mmcAudio_Done(NotifyCode As Integer)
  37.     mmcAudio.Command = "Close"
  38.     lblAudio.Caption = ""
  39.     cmdPlay.Caption = "Play"
  40. End Sub
  41.  
  42. Private Sub Form_Unload(Cancel As Integer)
  43.     ' Close the multimedia device.
  44.     mmcAudio.Command = "Close"
  45. End Sub
  46.  
  47.  
Hopefully this is what you wanted. Let us know if it works, just found this one...
Thank you very much for this reply, I did know it is so long like that, the code to start play some sound of ( .WAV ) type, uses OLE control, I though it is similar for stoping it too?

but any way I am going to try it and let you know

Thank you

M C Benzerari
Aug 8 '07 #3
Sorry! I wanted to say:

Thank you very much for this reply, I did NOT know it is so long like that, the code to start play some sound of ( .WAV ) type, uses OLE control, I though it is similar for stoping it too?

but any way I am going to try it and let you know


As there is no way to correct a thread once added...

Thank you

M C Benzerari
Aug 9 '07 #4
Give this a whirl, Benzerari:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. Dim app_path As String
  4.  
  5.     app_path = App.Path
  6.     If Right$(app_path, 1) <> "\" Then app_path = app_path _
  7.         & "\"
  8.     txtFile.Text = app_path & "Alice_Cooper-Gimmie.mp3"
  9.  
  10.     ' Prepare the audio control.
  11.     mmcAudio.Notify = False
  12.     mmcAudio.Wait = True
  13.     mmcAudio.Shareable = False
  14.     mmcAudio.Command = "Close"
  15. End Sub
  16.  
  17. ' Play the MP3 file.
  18. Private Sub cmdPlay_Click()
  19.     If cmdPlay.Caption = "Play" Then
  20.         mmcAudio.FileName = txtFile.Text
  21.         mmcAudio.Command = "Open"
  22.         mmcAudio.Command = "Play"
  23.         cmdPlay.Caption = "Stop"
  24.     Else
  25.         mmcAudio.Command = "Stop"
  26.         mmcAudio.Command = "Close"
  27.     End If
  28. End Sub
  29.  
  30. Private Sub mmcAudio_StatusUpdate()
  31.     lblAudio.Caption = mmcAudio.Position & "/" & _
  32.         mmcAudio.Length
  33. End Sub
  34.  
  35. ' Prepare the control to play again.
  36. Private Sub mmcAudio_Done(NotifyCode As Integer)
  37.     mmcAudio.Command = "Close"
  38.     lblAudio.Caption = ""
  39.     cmdPlay.Caption = "Play"
  40. End Sub
  41.  
  42. Private Sub Form_Unload(Cancel As Integer)
  43.     ' Close the multimedia device.
  44.     mmcAudio.Command = "Close"
  45. End Sub
  46.  
  47.  
Hopefully this is what you wanted. Let us know if it works, just found this one...
Please can you send me a sketch of how the form related to the above code looks like, with enough details,...also you can send it as an attachement to benzerari1966@yahoo.com. as there is no way to attach it in the forum

Thank you

M C Benzerari
Aug 9 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by MFC | last post: by
7 posts views Thread by Lee Moody | last post: by
4 posts views Thread by Fredrik Melin | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
6 posts views Thread by =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.