In the previous lesson, you have create a DVD player. Now, by making some modifications, you can transform the DVD player into an audio player. This player will have the capability to search and play sound files in your storage devices such as a hard drive.
In this project, you need to insert a ComboBox, a DriveListBox, a DirListBox, a TextBox and a FileListBox into your form. We Shall briefly examine the function of each of the above controls. Besides, you must also insert Microsoft Multimedia Control(MMControl) into your form , you may make it visible or invisible. In this program, we choose to make it invisible so that we can use the command buttons created to control the player.
Relevant code must be written to coordinate all the above controls so that the application can work properly. The program should follow in the following logical way:
Step 1: User chooses the type of files he wants to play.
Step2:User selects the drive that might contains the relevant audio files.
Step 3:User looks into directories and subdirectories for the files specified in step1. The files should be displayed in the FileListBox.
Step 4: User selects the files from the FileListBox and click the Play button.
Step 5: User clicks on the Stop button to stop playing and Exit button to end the application.
Private Sub Combo1_Change() ' to determine file type If ListIndex = 0 Then File1.Pattern = ("*.wav") ElseIf ListIndex = 1 Then File1.Pattern = ("*.mid") Else Fiel1.Pattern = (";*.*") End If End Sub
Private Sub Dir1_Change() 'To change directories and subdirectories File1.Path = Dir1.Path If Combo1.ListIndex = 0 Then File1.Pattern = ("*.wav") ElseIf Combo1.ListIndex = 1 Then File1.Pattern = ("*.mid") Else File1.Pattern = ("*.*") End If End Sub
Private Sub play_Click() 'To play WaveAudio file or Midi File If Combo1.ListIndex = 0 Then AudioPlayer.DeviceType ="WaveAudio" ElseIf Combo1.ListIndex = 1 Then AudioPlayer.DeviceType ="Sequencer" End If AudioPlayer.FileName = Text1.Text AudioPlayer.Command = "Open" AudioPlayer.Command = "Play" End Sub
Private Sub stop_Click() If AudioPlayer.Mode = 524 Then Exit Sub If AudioPlayer.Mode <>525 Then AudioPlayer.Wait = True AudioPlayer.Command = "Stop" End If AudioPlayer.Wait = True AudioPlayer.Command = "Close" End Sub
Private Sub Drive1_Change() 'To change drives Dir1.Path = Drive1.Drive End Sub
Private Sub File1_Click() If Combo1.ListIndex = 0 Then File1.Pattern = ("*.wav") ElseIf Combo1.ListIndex = 1 Then File1.Pattern = ("*.mid") Else File1.Pattern = ("*.*") End If If Right(File1.Path, 1)<>"\" Then filenam = File1.Path + "\" + File1.FileName Else filenam = File1.Path + File1.FileName End If Text1.Text = filenam End Sub
Private Sub Form_Load() 'To center the Audioplayer startup page Left = (Screen.Width - Width) \ 2 Top = (Screen.Height - Height) \ 2 Combo1.Text = "*.wav" Combo1.AddItem "*.wav" Combo1.AddItem "*.mid" Combo1.AddItem "All files" End Sub