player in vb6
Pagina 1 din 1
player in vb6
In acest tutorial o sa va arat cum sa faceti un foarte simplu player mp3..
Mai intai declarati aceste 2 functii:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
iar apoi o variabila de tip String:
Dim r as String
Acum pe form punem un buton(Caption="Open") cu care vom deschide o melodie...pentru asta ne trebuie componenta CommonDialog(Microsoft Common Dialog Control 6) pe cae o vom numi mai prescertat cd1(Name="cd1")
Acum punem un button(Caption="Play") prin care vom asculta melodia selectata!
Mai punem un buton Pause si unul Stop..
Ne mai trebuie un Timer cu intervalul 100..(Enabled=False)
Codul pentru butonuul "Open":
Dim mp3Filename As String * 1024, mp3Length As String * 30
cd1.ShowOpen
If cd1.FileName <> "" Then
r = GetShortPathName(cd1.FileName, mp3Filename, 1024)
mp3Filename = Left(mp3Filename, r)
r = mciSendString("Open " & mp3Filename & " Alias MP3", 0&, 0, 0)
r = mciSendString("status MP3 length", mp3Length, 30, 0)
PrgBar.Max = CLng(mp3Length)
End If
Text1.Text = cd1.FileName
am mai pus un textbox(Text1) in care se afiseaza melodia selectata(FileName)
Codul pentru butonul Play:
r = mciSendString("Play MP3", 0&, 0, 0)
Timer1.Enabled = True
Codul pentru butonul Pause:
r = mciSendString("Pause MP3", 0&, 0, 0)
Codul pentru butonul Stop:
r = mciSendString("Stop MP3", 0&, 0, 0) 'opreste melodia
r = mciSendString("Close MP3", 0&, 0, 0) 'iar apoi o opreste
Timer1.Enabled = False
acum codul pentru timer:
Dim mp3Position As String * 30
r = mciSendString("Set Mp3 time format milliseconds", 0, 0, 0)
r = mciSendString("Status MP3 position", mp3Position, 30, 0)
PrgBar.Value = CLng(mp3Position)
aici vedeti ca a aprut o componenta noua(PrgBar)- etse un progrosbar(Microsoft Windows Common Controls 6) ProgressBar9prescurtarea e PrgBar in cazul meu)
si cam atat..Daca mai doriti sa va arate si durata melodiei mai puneti un label (Label1) si puneti codul tot la Timer1
Label1.caption = Format(CLng(mp3Position), "00:00:00:000")
Codul final al Timerului ar trebui sa arate cam asa dupa ce puneti si labelul:
Dim mp3Position As String * 30
r = mciSendString("Set Mp3 time format milliseconds", 0, 0, 0)
r = mciSendString("Status MP3 position", mp3Position, 30, 0)
PrgBar.Value = CLng(mp3Position)
Label1.caption = Format(CLng(mp3Position), "00:00:00:000")
succes
Mai intai declarati aceste 2 functii:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
iar apoi o variabila de tip String:
Dim r as String
Acum pe form punem un buton(Caption="Open") cu care vom deschide o melodie...pentru asta ne trebuie componenta CommonDialog(Microsoft Common Dialog Control 6) pe cae o vom numi mai prescertat cd1(Name="cd1")
Acum punem un button(Caption="Play") prin care vom asculta melodia selectata!
Mai punem un buton Pause si unul Stop..
Ne mai trebuie un Timer cu intervalul 100..(Enabled=False)
Codul pentru butonuul "Open":
Dim mp3Filename As String * 1024, mp3Length As String * 30
cd1.ShowOpen
If cd1.FileName <> "" Then
r = GetShortPathName(cd1.FileName, mp3Filename, 1024)
mp3Filename = Left(mp3Filename, r)
r = mciSendString("Open " & mp3Filename & " Alias MP3", 0&, 0, 0)
r = mciSendString("status MP3 length", mp3Length, 30, 0)
PrgBar.Max = CLng(mp3Length)
End If
Text1.Text = cd1.FileName
am mai pus un textbox(Text1) in care se afiseaza melodia selectata(FileName)
Codul pentru butonul Play:
r = mciSendString("Play MP3", 0&, 0, 0)
Timer1.Enabled = True
Codul pentru butonul Pause:
r = mciSendString("Pause MP3", 0&, 0, 0)
Codul pentru butonul Stop:
r = mciSendString("Stop MP3", 0&, 0, 0) 'opreste melodia
r = mciSendString("Close MP3", 0&, 0, 0) 'iar apoi o opreste
Timer1.Enabled = False
acum codul pentru timer:
Dim mp3Position As String * 30
r = mciSendString("Set Mp3 time format milliseconds", 0, 0, 0)
r = mciSendString("Status MP3 position", mp3Position, 30, 0)
PrgBar.Value = CLng(mp3Position)
aici vedeti ca a aprut o componenta noua(PrgBar)- etse un progrosbar(Microsoft Windows Common Controls 6) ProgressBar9prescurtarea e PrgBar in cazul meu)
si cam atat..Daca mai doriti sa va arate si durata melodiei mai puneti un label (Label1) si puneti codul tot la Timer1
Label1.caption = Format(CLng(mp3Position), "00:00:00:000")
Codul final al Timerului ar trebui sa arate cam asa dupa ce puneti si labelul:
Dim mp3Position As String * 30
r = mciSendString("Set Mp3 time format milliseconds", 0, 0, 0)
r = mciSendString("Status MP3 position", mp3Position, 30, 0)
PrgBar.Value = CLng(mp3Position)
Label1.caption = Format(CLng(mp3Position), "00:00:00:000")
succes
Pagina 1 din 1
Permisiunile acestui forum:
Nu puteti raspunde la subiectele acestui forum
|
|