VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Random Wav Player

by Andy T. (3 Submissions)
Category: Sound/MP3
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

I was really bored today, so I made a completely useless little program that selects a random .wav from a specified folder, plays it and then closes. It could be put in the startup folder and used to play a random .wav sound when Windows starts (as a replacement for the Windows sounds), or any other event.

Assumes
If you use this at Windows Startup, disable the "Start Windows" sound in the Control Panel > Sounds utility. Put this code on a blank form named "Form1" and change the folder that it searches.

Rate Random Wav Player

Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" _
  (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
' If you use this at Windows Startup, disable the "Start Windows" sound in the Control Panel > Sounds utility.
Sub PlaySound()
  Dim fsoFileSystem, fsoFolder, fsoFile, fsoFolderFiles
  Dim strWavs(0 To 50) As String
  Dim intCounter As Integer
  Dim strFileName As String
  
  intCounter = 0
  
  Set fsoFileSystem = CreateObject("Scripting.FileSystemObject")
  Set fsoFolder = fsoFileSystem.GetFolder("c:\winnt\media") '<< OR WHATEVER FOLDER YOU WANT
  Set fsoFolderFiles = fsoFolder.Files
  For Each fsoFile In fsoFolderFiles
    If Right(fsoFile.Name, 4) = ".wav" Then
      strWavs(intCounter) = fsoFile.Name
      intCounter = intCounter + 1
    End If
  Next
  
  strFileName = strWavs(Int(Rnd * intCounter))
  Call sndPlaySound32(fsoFolder & "\" & strFileName, 0)
End Sub
Private Sub Form_Load()
  Form1.Visible = False
  PlaySound
  End
  '(pretty simple, huh?)
End Sub

Download this snippet    Add to My Saved Code

Random Wav Player Comments

No comments have been posted about Random Wav Player. Why not be the first to post a comment about Random Wav Player.

Post your comment

Subject:
Message:
0/1000 characters