当前位置:编程学习 > VB >>

关于VB编程问题

我想写一个vb程序,让他控制一个播放器,包括开始,暂停,停止等,还要控制它播放某一个视频文件,用什么指令或方法可以实现,请高手赐教!!!
答案:

作者:FlyMe

联系方式:7826-452-10

看到有好多同学要视频播放器的代码,就弄了一个,相互学习一下

Dim joke As Boolean
Dim filename(10) As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim switch As Boolean
Private Declare Function CreateEllipticRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, ByVal hrgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function auxSetVolume Lib "winmm.dll" _
(ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
Private Declare Function waveOutGetVolume Lib "winmm.dll" _
(ByVal uDeviceID As Long, lpdwVolume As Long) As Long

Private Declare Function waveOutSetVolume Lib "winmm.dll" _
(ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long




Private Sub Add_Click()
CommonDialog1.Filter = "AVI|*.avi|WAV|*.wav|MID|*.mid|MPG|*.mpg|MP3|*.mp3|所有文件|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.filename <> "" Then
     filename(i) = CommonDialog1.filename
     List1.AddItem (filename(i))
     i = i + 1
End If
End Sub
Private Sub Closeb_Click()
MC.Command = "close"
MC.filename = ""
Label2.Caption = "No File"
MC.PlayEnabled = False
MC.PrevEnabled = False
MC.NextEnabled = False
MC.StepEnabled = False
MC.BackEnabled = False

End Sub
Private Sub Combo1_Change()
Select Case Combo1.Text
Case "WAV"
   File1.Pattern = "*.wav"
Case "AVI"
   File1.Pattern = "*.avi"
Case "MID"
   File1.Pattern = "*.mid"
Case "MPG"
   File1.Pattern = "*.mpg"
Case "MP3"
   File1.Pattern = "*.mp3"
End Select
End Sub
Private Sub Combo1_Click()
Select Case Combo1.Text
Case "WAV"
   File1.Pattern = "*.wav"
Case "AVI"
   File1.Pattern = "*.avi"
Case "MID"
   File1.Pattern = "*.mid"
Case "MPG"
   File1.Pattern = "*.mpg"
Case "MP3"
   File1.Pattern = "*.mp3"
End Select
End Sub

Private Sub Command1_Click()
a = auxSetVolume(uBeviceID, 15)
End Sub

Private Sub dall_Click()
List1.Clear
MC.filename = ""
Label2.Caption = "No File"
MC.BackEnabled = False
MC.StepEnabled = False
MC.Command = "close"
MC.PlayEnabled = False
MC.PrevEnabled = False
MC.NextEnabled = False


End Sub
Private Sub Delete_Click()
If List1.ListIndex <= 9 And List1.ListIndex >= 0 Then
k = List1.ListIndex
List1.RemoveItem (List1.ListIndex)
i = i - 1
End If
For k = k To 8
filename(k) = filename(k + 1)
If filename(k + 2) = "" Then
   Exit For
End If
Next k
filename(i + 1) = ""
MC.filename = ""
Label2.Caption = "No File"


If i = 0 Then
MC.filename = ""
Label2.Caption = "No File"
MC.BackEnabled = False
MC.StepEnabled = False
MC.Command = "close"
MC.PlayEnabled = False
MC.PrevEnabled = False
MC.NextEnabled = False
End If
End Sub
Private Sub Dir1_Change()
File1.filename = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Exitb_Click()
MC.Command = "close"
Unload Form1
End Sub
Private Sub File1_DblClick()
MC.Command = "close"
Select Case Combo1.Text
Case "AVI"
   MC.DeviceType = "AVIVideo"
Case "WAV"
   MC.DeviceType = "waveaudio"
Case "MID"
   MC.DeviceType = "Sequencer"
Case "MPG"
   MC.DeviceType = "MPEGVideo"
Case "MP3"
   MC.DeviceType = "MPEGVideo"
End Select
MC.filename = Dir1.Path + "\" + File1.filename
MC.Command = "open"
MC.PlayEnabled = True
MC.PrevEnabled = True
MC.NextEnabled = True
End Sub

Private Sub File1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Image1.Move File1.Left, File1.Top + y - 70, File1.Width, 200
Image1.Drag
End Sub

Private Sub Form_Load()
Dim lreg As Long
hrgn = CreateEllipticRgn(0, 0, 800, 600)
lres = SetWindowRgn(Me.hWnd, hrgn, True)
MC.Command = "open"
i = 0
j = 25
l = 25
joke = False
Timer1.Interval = 35
switch = True
Combo1.AddItem ("AVI")
Combo1.AddItem ("WAV")
Combo1.AddItem ("MID")
Combo1.AddItem ("MPG")
Combo1.AddItem ("MP3")
Timer1.Enabled = False
Label1.Visible = False
File1.Pattern = "*.wav"
Form1.MousePointer = 2


End Sub
Private Sub List1_DblClick()
MC.Command = "close"
MC.filename = filename(List1.ListIndex)
MC.Command = "open"
Combo1.Text = UCase(Mid(MC.filename, Len(MC.filename) - 2, 3))
MC.PlayEnabled = True
MC.PrevEnabled = True
MC.NextEnabled = True
If i >= 2 Then
MC.StepEnabled = True
MC.BackEnabled = True
End If
End Sub

Private Sub List1_DragDrop(Source As Control, x As Single, y As Single)
filename(i) = Dir1.Path + "\" + File1.filename
     List1.AddItem (filename(i))
     i = i + 1
End Sub

Private Sub MC_BackClick(Cancel As Integer)
MC.Command = "close"
If List1.ListIndex = 0 Then
MC.filename = filename(i)
List1.ListIndex = i - 1
MC.Command = "open"
ElseIf List1.ListIndex >= 1 Then
   MC.filename = filename(List1.ListIndex - 1)
   List1.ListIndex = List1.ListIndex - 1
   MC.Command = "open"
End If


End Sub

Private Sub MC_Done(NotifyCode As Integer)
'MC.StopEnabled = False
MC.PauseEnabled = False
End Sub

Private Sub MC_NextClick(Cancel As Integer)
MC.PlayEnabled = True
End Sub

Private Sub MC_PlayClick(Cancel As Integer)
Label2.Caption = MC.filename
MC.StopEnabled = True
MC.PauseEnabled = True
MC.PlayEnabled = False
End Sub

Private Sub MC_PrevClick(Cancel As Integer)
MC.StopEnabled = True
End Sub

Private Sub MC_StepClick(Cancel As Integer)
MC.Command = "close"
If List1.ListIndex = i - 1 Then
MC.filename = filename(0)
List1.ListIndex = 0
MC.Command = "open"
ElseIf List1.ListIndex < i - 1 Then
   MC.filename = filename(List1.ListIndex + 1)
   List1.ListIndex = List1.ListIndex + 1
   MC.PlayEnabled = True
   MC.Command = "open"
End If

End Sub

Private Sub MC_StopClick(Cancel As Integer)
MC.StopEnabled = False
MC.PauseEnabled = False
MC.PlayEnabled = True
End Sub


Private Sub Openb_Click()
CommonDialog1.Filter = "AVI|*.avi|WAV|*.wav|MID|*.mid|MPG|*.mpg|MP3|*.mp3|所有文件|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.filename <> "" Then
   MC.filename = CommonDialog1.filename
   MC.Command = "open"
   Combo1.Text = UCase(Mid(MC.filename, Len(MC.filename) - 2, 3))
End If
End Sub



Private Sub Timer1_Timer()
Label1.Left = Label1.Left + j
Label1.Top = Label1.Top + l
If Label1.Left > 8000 Or Label1.Left < 3000 Then
j = -j
End If
If Label1.Top < 1200 Or Label1.Top > 5000 Then
l = -l
End If


End Sub





添加WindowsMediaPlayer控件,具体使用方法参照msdn

上一个:求Vb编程代码
下一个:关于VB的API

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,