VB播放视频文件代码
需要制作一个窗体,以窗体上的按钮调动系统上的播放器播放一段视频,窗体程序与视频在同一文件夹下,视频格式有avi、mpg、wmv等,由于视频在不同的电脑上播放,播放器的路径...
需要制作一个窗体,以窗体上的按钮调动系统上的播放器播放一段视频,窗体程序与视频在同一文件夹下,视频格式有avi、mpg、wmv等,由于视频在不同的电脑上播放,播放器的路径与程序都是不确定的,本人没学过VB,现急求一段这样的代码,给代码就好,因为窗体的样式可能自己还要改,非常感谢!
展开
3个回答
展开全部
将以下文本 复制到 记事本里 然后另存为form1.frm
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3480
ClientLeft = 60
ClientTop = 450
ClientWidth = 8460
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 3480
ScaleWidth = 8460
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.FileListBox File1
Height = 2430
Left = 1200
TabIndex = 3
Top = 600
Width = 6975
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 1
Text = "Text1"
Top = 120
Width = 6975
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 600
Left = 120
TabIndex = 0
Top = 720
Width = 990
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 240
Top = 1440
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "视频文件名最好不要带空格"
Height = 315
Left = 3240
TabIndex = 4
Top = 3120
Width = 2520
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "播放器路径"
Height = 195
Left = 120
TabIndex = 2
Top = 240
Width = 900
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub File1_DblClick()
On Error Resume Next
s = " " & File1.Path & "\" & File1.List(File1.ListIndex)
x = Shell(Text1.Text & s, 1)
Resume
End Sub
Private Sub Form_Load()
'添加microsoft Common Dialog control 控件
'commandbox textbox filelistbox
Command1.Caption = "选择播放器路径"
File1.Path = App.Path
File1.Pattern = "*.rmvb;*.wmv;*.mpg;*.avi;*.rm"
End Sub
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3480
ClientLeft = 60
ClientTop = 450
ClientWidth = 8460
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 3480
ScaleWidth = 8460
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.FileListBox File1
Height = 2430
Left = 1200
TabIndex = 3
Top = 600
Width = 6975
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 1
Text = "Text1"
Top = 120
Width = 6975
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 600
Left = 120
TabIndex = 0
Top = 720
Width = 990
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 240
Top = 1440
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "视频文件名最好不要带空格"
Height = 315
Left = 3240
TabIndex = 4
Top = 3120
Width = 2520
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "播放器路径"
Height = 195
Left = 120
TabIndex = 2
Top = 240
Width = 900
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub File1_DblClick()
On Error Resume Next
s = " " & File1.Path & "\" & File1.List(File1.ListIndex)
x = Shell(Text1.Text & s, 1)
Resume
End Sub
Private Sub Form_Load()
'添加microsoft Common Dialog control 控件
'commandbox textbox filelistbox
Command1.Caption = "选择播放器路径"
File1.Path = App.Path
File1.Pattern = "*.rmvb;*.wmv;*.mpg;*.avi;*.rm"
End Sub
展开全部
需要特别强调的是WindowsMediaPlayer控件是调用你本机的WindowsMediaPlayer播放器,而WindowsMediaPlayer的默认支持的播放格式为wma、mp3、asf。还有WindowsMediaPlayer1.Controls = play不能用的 吧 这控件都没有Controls这个属性,所以不能用的吧 我直接这样是可以的Private Sub Form_Load()
WindowsMediaPlayer1.URL = "E:\music\beyond\Beyond.Live.1991_C.mp3"End Sub
WindowsMediaPlayer1.URL = "E:\music\beyond\Beyond.Live.1991_C.mp3"End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim WshShell
Set WshShell = CreateObject("Shell.Application")
WshShell.open "c:\mp3\qq.mp3" '此处根据实际修改播放的文件名
End Sub
Dim WshShell
Set WshShell = CreateObject("Shell.Application")
WshShell.open "c:\mp3\qq.mp3" '此处根据实际修改播放的文件名
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询