Search Tools Links Login

Random Wav Player


Visual Basic 6, or VB Classic

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.

Original Author: Andy T.

Assumptions

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.

Code

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:winntmedia") '<< 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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 83 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.