Program Multimedia
In the first discussion of this, I will give you the tricks how to create a multimedia applications or programs such as Winamp, which is able to run the mp3 files। To make this program we do not use the components of Windows Media Player version does not। In creating this program, the software we use Visual Basic 2005.
The ability of this program are:
a.Ikon program into the systray, not to the taskbar. So, we raise the window with this program and choose the menu icon in the systray this program.
b.Kita can adjust the volume difference between right and left speakers, can memute.
c.Terdapat sequence of songs (mp3)
d.Lagu can be selected in the folder you
e।Informasi name of the song can be displayed in animation.
- File Class Module clsAudio
Enter the code Region Declaration of variables and functions of the Windows API such as the following:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private _Filename As String = Nothing
Private _volLevel As Integer = Nothing
Private _muteOutput As Boolean = False
Private _rChanValue As Boolean = False
Private _lChanValue As Boolean = False
Private _rChanVol As Integer = Nothing
Private _lChanVol As Integer = Nothing
Private _playSpeed As Integer = Nothing
Private WithEvents waktu As New Timer
Declare a local (Private) use the Windows API mciSendString. Useless to send commands to the audio devices to run and certain audio files.
Pendeklarasian variable _filename local and general nature, useful for collecting data address audio files that run.
_volLevel Recognized variables that are useful to accommodate the large volume of audio used.
_muteOutput Recognized variables that are useful to accommodate speakers in the overall sound is muted or not.
_iChanValue Recognized variables that are useful for collecting the data is sound speakers left in muted or not.
_ChanVol Recognized variables that are useful to accommodate the large volume of data right speakers.
_iChanVol Recognized variables that are useful to accommodate the large volume of data speakers left.
_playSpeed Recognized variables that are useful to accommodate the data speed of sound, which is run.
Pendeklarasian the use of variable time as the control timer event along with it.
Code is included in the regional event are:
Public Event Playing()
Public Event Berhenti()
Public Event Kesalahan(ByVal info As String)
To set the event and class modules, the Public Event followed by the name of the event we want. If you want to generate Event is in a class module in the procedur we used the name RaiseEvent and followed that ditimbulkannya Event.
The code that we want to enter the region included in the next, the key region:
#Region "Tombol"
Public Sub PlayAudio()
Try
mciSendString("close song", 0, 0, 0)
mciSendString("open " & filename & " alias song", 0, 0, 0)
mciSendString("play song", 0, 0, 0)
waktu.Enabled = True
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
End Try
End Sub
Public Sub StopAudio()
Try
mciSendString("stop song", 0, 0, 0)
waktu.Enabled = False
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
End Try
End Sub
Public Sub PauseAudio()
Try
mciSendString("pause song", 0, 0, 0)
waktu.Enabled = False
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
End Try
End Sub
Public Sub ResumeAudio()
Try
mciSendString("resume song", 0, 0, 0)
waktu.Enabled = True
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
End Try
End Sub
Public Sub CloseAudio()
Try
mciSendString("close all", 0, 0, 0)
waktu.Enabled = False
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
End Try
End Sub
#End Region
Code that is inserted in the region and InfoDurasi Position is:
Public ReadOnly Property PosisiInSec() As Integer
Get
Dim stat As String = Space(128)
mciSendString("set song time format milliseconds", 0, 0, 0)
mciSendString("status song position", stat, 128, 0)
Return Val(stat) / 1000
stat = Nothing
End Get
End Property
Public ReadOnly Property DurasiInSec() As Integer
Get
Dim totalTime As String = Space(128)
mciSendString("status song length", totalTime, 128, 0&)
Return Val(totalTime) / 1000
totalTime = Nothing
End Get
End Property
Public ReadOnly Property SisaWaktuInSec() As Integer
Get
Return (DurasiInSec - PosisiInSec)
End Get
End Property
Public ReadOnly Property formatPosisi() As String
Get
Dim sec As Integer = Val(PosisiInSec())
If sec < style="color: blue;">Then
Return "0:" & Format(sec, "00")
Else
Dim mins As Integer = Int(sec / 60)
sec = sec - (mins * 60)
Return Format(mins, "0") & ":" & Format(sec, "00")
End If
End Get
End Property
Public ReadOnly Property formatDurasi() As String
Get
Dim stat As String = Space(128)
mciSendString("set song time format ms", stat, 128, 0)
mciSendString("status song length", stat, 128, 0)
Return getThisTime(Val(stat))
End Get
End Property
Public ReadOnly Property formatSisaWaktu() As String
Get
Return getThisTime(SisaWaktuInSec * 1000)
End Get
End Property
Private Function getThisTime(ByVal timein As Integer) As String
Try
Dim remTime As Integer = timein / 1000
Dim conH As Integer = Int(remTime / 3600)
remTime = remTime Mod 3600
Dim conM As Integer = Int(remTime / 60)
remTime = remTime Mod 60
Dim conS As Integer = remTime
Dim strRetTime As String
If conH > 0 Then
strRetTime = Trim(Str(conH)) & ":"
Else
strRetTime = ""
End If
If conM >= 10 Then
strRetTime = strRetTime & Trim(Str(conM))
ElseIf conM > 0 Then
strRetTime = strRetTime & Trim(Str(conM))
Else
strRetTime = strRetTime & "0"
End If
strRetTime = strRetTime & ":"
If conS >= 10 Then
strRetTime = strRetTime & Trim(Str(conS))
ElseIf conS > 0 Then
strRetTime = strRetTime & "0" & Trim(Str(conS))
Else
strRetTime = strRetTime & "00"
End If
Return strRetTime
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
Return Nothing
End Try
End Function
In this region we make the properties - properties of the object to provide information about the way the audio files.
Code is included in the regional Audio Volume is:
Public Property volumeLevel() As Integer
Get
Dim theLevel As String = Space(128)
mciSendString("status song volume", theLevel, 128, 0)
_volLevel = Val(theLevel)
Return _volLevel
theLevel = Nothing
_volLevel = Nothing
End Get
Set(ByVal Value As Integer)
mciSendString("setaudio song volume to " & Value, 0, 0, 0)
End Set
End Property
Public Property muteSoundOutput() As Boolean
Get
muteSoundOutput = _muteOutput
End Get
Set(ByVal Value As Boolean)
If Value = True Then
mciSendString("set song audio all off", 0, 0, 0)
_muteOutput = Value
Else
mciSendString("set song audio all on", 0, 0, 0)
_muteOutput = Value
End If
End Set
End Property
Public Property rightChannelMute() As Boolean
Get
rightChannelMute = _rChanValue
End Get
Set(ByVal Value As Boolean)
If Value = True Then
mciSendString("setaudio song right off", 0, 0, 0)
_rChanValue = Value
Else
mciSendString("setaudio song right on", 0, 0, 0)
_rChanValue = Value
End If
End Set
End Property
Public Property leftChannelMute() As Boolean
Get
leftChannelMute = _lChanValue
End Get
Set(ByVal Value As Boolean)
If Value = True Then
mciSendString("setaudio song left off", 0, 0, 0)
_lChanValue = Value 'True
Else
mciSendString("setaudio song left on", 0, 0, 0)
_lChanValue = Value 'False
End If
End Set
End Property
Public Property leftVolume() As Integer
Get
Dim leftLevel As String = Space(128)
mciSendString("status song left volume", leftLevel, 128, 0)
_lChanVol = Val(leftLevel)
leftVolume = _lChanVol
leftLevel = Nothing
_lChanVol = Nothing
End Get
Set(ByVal Value As Integer)
mciSendString("setaudio song left volume to " & Value, 0, 0, 0)
End Set
End Property
Public Property rightVolume() As Integer
Get
Dim rightlevel As String = Space(128)
mciSendString("status song right volume", rightlevel, 128, 0)
_rChanVol = Val(rightlevel)
rightVolume = _rChanVol
rightlevel = Nothing
_rChanVol = Nothing
End Get
Set(ByVal Value As Integer)
mciSendString("setaudio song right volume to " & Value, 0, 0, 0)
End Set
End Property
Created a new property called volumelabel useful to get the volume level and set the volume of songs.
Code in the region other is the code that can not be included in the group above. Codes are:
Public Property filename() As String
Get
Return _Filename
'waktu.Enabled = True
End Get
Set(ByVal Value As String)
_Filename = Chr(34) + Trim(Value) + Chr(34)
End Set
End Property
Public ReadOnly Property deviceName() As String
Get
Dim theData As String = Space(128)
mciSendString("sysinfo song installname", theData, 128, 0)
Return theData
End Get
End Property
Public ReadOnly Property isPlaying() As Boolean
Get
Dim stat As String = Space(7)
mciSendString("status song mode", stat, 128, 0)
If stat = "playing" Then
Return True
waktu.Enabled = True
Else
Return False
End If
End Get
End Property
Public Property AturKecepatan() As Integer
Get
Dim rate As String = Space(128)
mciSendString("status song speed", rate, 128, 0)
_playSpeed = Val(rate)
Return _playSpeed
End Get
Set(ByVal Value As Integer)
mciSendString("set song speed " & Value, "", 0, 0)
End Set
End Property
Public Sub RubahPosisi(ByVal theSecond As Integer)
Try
theSecond = theSecond * 1000
If isPlaying = True Then mciSendString("play song from " & theSecond, 0, 0, 0)
If isPlaying = False Then mciSendString("seek song to " & theSecond, 0, 0, 0)
Catch exc As Exception
RaiseEvent Kesalahan(exc.Message)
End Try
End Sub
Private Sub waktu_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles waktu.Tick
If isPlaying = True Then
RaiseEvent Playing()
Else
RaiseEvent Berhenti()
waktu.Enabled = False
End If
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
Public Sub New()
MyBase.New()
End Sub
End Class
* File Form frmMusik
The appearance of our program during runtime image as follows:
Code entered in this form are:
a। Deklarasi variables and object, which contains the variable declaration and a new object
Private WithEvents audio As New clsAudio
Dim lstpathfiles As New ListBox
Dim indexlst As Integer
Dim animstart As Integer
Dim animlong As Integer
। .MenuFileList, related penginputan value to the ListBox in the file, namely lstFiles.
Private Sub mnuAddFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddFolder.Click
Dim browse As New FolderBrowserDialog
With browse
.Description = "Pilih Alamat Folder Lagu"
.ShowDialog()
For Each file As System.IO.FileInfo In My.Computer.FileSystem.GetDirectoryInfo(.SelectedPath.ToString).GetFiles
If file.Extension.ToUpper = ".MP3" Or file.Extension.ToUpper = ".WAV" Or file.Extension.ToUpper = ".WMA" Or file.Extension.ToUpper = ".MID" Then
lstFiles.Items.Add(Strings.Left(file.Name, file.Name.Length - 4))
lstpathfiles.Items.Add(file.FullName)
End If
Next
End With
End Sub
Private Sub mnuAddFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddFile.Click
Dim openDg As New OpenFileDialog
With openDg
.Filter = "Supported Files (*.mp3, *.wav, *.wma, *.mid)|*.mp3;*.wav;*.wma;*.mid"
Dim dlgResult As DialogResult = .ShowDialog
If dlgResult = Windows.Forms.DialogResult.Cancel Then Exit Sub
Dim tmp As String = NamaFile(.FileName)
lstFiles.Items.Add(Strings.Left(tmp, tmp.Length - 4))
lstpathfiles.Items.Add(.FileName)
End With
End Sub
Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
If MsgBox("Hapus semua file yang ada ?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
lstFiles.Items.Clear()
lstpathfiles.Items.Clear()
End If
End Sub
Private Function NamaFile(ByVal Fullpath As String) As String
Try
Return My.Computer.FileSystem.GetFileInfo(Fullpath).Name
Catch ex As Exception
Return ""
End Try
End Function
c। Tombol, associated with key Play, Stop and Pause. Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
Playing()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
audio.StopAudio()
trbPlaying.Value = 0
lblPosisi.Text = "0:00"
Timer1.Enabled = False
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
If btnPause.Text = "Pause" Then
audio.PauseAudio()
btnPause.Text = "Resume"
Else
audio.ResumeAudio()
btnPause.Text = "Pause"
End If
End Sub
d। Muted Checkbox, related by the muted by some checkboxes.
Private Sub chkMuteAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMuteAll.CheckedChanged
If chkMuteAll.Checked = True Then
audio.muteSoundOutput = True
Else
audio.muteSoundOutput = False
End If
End Sub
Private Sub chkLeftMute_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLeftMute.CheckedChanged
If chkLeftMute.Checked = True Then
audio.leftChannelMute = True
Else
audio.leftChannelMute = False
End If
End Sub
Private Sub chkRightMute_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRightMute.CheckedChanged
If chkRightMute.Checked = True Then
audio.rightChannelMute = True
Else
audio.rightChannelMute = False
End If
End Sub
e। TrackBar, related to the trackbar volume, the volume comparison between left and right, and trackbar track position।
Private Sub trbVolume_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trbVolume.ValueChanged
audio.volumeLevel = trbVolume.Value * 200
End Sub
Private Sub trbPerbandingan_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trbPerbandingan.ValueChanged
Select Case trbPerbandingan.Value
Case 0
audio.leftVolume = 0
audio.rightVolume = 1000
Case 1
audio.leftVolume = 333
audio.rightVolume = 1000
Case 2
audio.leftVolume = 1000
audio.rightVolume = 1000
Case 3
audio.leftVolume = 1000
audio.rightVolume = 333
Case 4
audio.leftVolume = 1000
audio.rightVolume = 0
End Select
End Sub
Private Sub trbPlaying_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trbPlaying.Scroll
audio.RubahPosisi(audio.DurasiInSec / trbPlaying.Maximum * trbPlaying.Value)
End Sub
f। Event clsAudio related to the events of clsAudio।
Private Sub audio_Berhenti() Handles audio.Berhenti
If indexlst <> lstpathfiles.Items.Count - 1 Then
indexlst = indexlst + 1
Else
If chkReplay.Checked = True Then
indexlst = 0
Else
Exit Sub
End If
End If
lstFiles.SelectedIndex = indexlst
Playing()
If Me.Visible = False Then
ico_Hide.ShowBalloonTip(10, "Judul", lstFiles.Items.Item(indexlst), ToolTipIcon.Info)
ico_Hide.Text = "Media Player" & vbCrLf & lstFiles.Items.Item(indexlst)
End If
End Sub
Private Sub audio_Playing() Handles audio.Playing
On Error Resume Next
lblSisaWaktu.Text = audio.formatSisaWaktu
trbPlaying.Value = audio.PosisiInSec
lblPosisi.Text = audio.formatPosisi
End Sub
g। Notify icon, associated with accessing the program icon in the systray।
Private Sub mnuNotifyIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNotifyIcon.Click, mnuHideico.Click
Me.Visible = False
ico_Hide.Text = "Media Player" & vbCrLf & lstFiles.Items.Item(indexlst)
End Sub
Private Sub mnuShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShow.Click
Me.WindowState = FormWindowState.Normal
Me.Visible = False
Me.Visible = True
ico_Hide.Text = "Media Player"
End Sub
Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
MsgBox("Media Player Net V.1" & vbCrLf & "Created by Wardana", MsgBoxStyle.Information)
End Sub
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
End
End Sub
h। others, contains the code other than the code above।
Private Sub lstFiles_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFiles.Click
On Error Resume Next
lblJudul.Text = lstFiles.Items.Item(lstFiles.SelectedIndex)
indexlst = lstFiles.SelectedIndex
Playing()
End Sub
Private Sub Playing()
audio.StopAudio()
audio = Nothing
audio = New clsAudio
With audio
.filename = lstpathfiles.Items.Item(indexlst)
.PlayAudio()
trbPlaying.Maximum = .DurasiInSec
lblSisaWaktu.Text = .formatDurasi
trbVolume.Value = .volumeLevel / 200
End With
animstart = 0
animlong = lstFiles.Items.Item(indexlst).Length
trbPlaying.Value = 0
Timer1.Enabled = True
End Sub
Private Sub mnuDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDel.Click
On Error Resume Next
lstFiles.Items.RemoveAt(lstFiles.SelectedIndex)
lstpathfiles.Items.RemoveAt(lstFiles.SelectedIndex)
End Sub
Private Sub frmMusic_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
audio.StopAudio()
audio.CloseAudio()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
On Error Resume Next
If lstpathfiles.Items.Count <> 0 Then
If lstFiles.Items.Item(indexlst) = "" Then Exit Sub
animstart = animstart + 1
If animstart = animlong Then animstart = 0
lblJudul.Text = Strings.Right(lstFiles.Items.Item(indexlst), animlong - animstart) + " " + Strings.Left(lstFiles.Items.Item(indexlst), animstart)
End If
End Sub
End Class
This the codes that have been included in the program. Then this program and build on his exe files can be taken on location at the address debug folder, where the program is stored or the data we publish in a place.
~ Reference program is taken from a book by the name of the author of "Wardana".
Read More..