Advertisement
3_2004-2005 Sound/MP3 #140626

Random Wav Player

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.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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
Original Comments (3)
Recovered from Wayback Machine