VB如何打开一个视频文件
高手请进.就是一单击按钮就可以播放视频PrivateSubCommand1_Click()CommonDialog1.ShowOpenWindowsMediaPlayer...
高手请进.
就是一单击按钮就可以播放视频
Private Sub Command1_Click()
CommonDialog1.ShowOpen
WindowsMediaPlayer1.URL = CommonDialog1.FileName
End Sub
上面代码中,为什么老是说找不文件.而且我不知道怎么输入视频文件
的位置.手把手的教教,拜托 展开
就是一单击按钮就可以播放视频
Private Sub Command1_Click()
CommonDialog1.ShowOpen
WindowsMediaPlayer1.URL = CommonDialog1.FileName
End Sub
上面代码中,为什么老是说找不文件.而且我不知道怎么输入视频文件
的位置.手把手的教教,拜托 展开
3个回答
展开全部
你得放上一个可以播放视频的控件才行,
Public Class 影音播放
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.InitialDirectory = "F:\Music"
OpenFileDialog1.Filter = "mp3 文件(*.mp3)|*.mp3|CD音频文件(*.wav)|*.wav|" & "视频(*.asf)|*.asf|所有文件(*.*)|*.*"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
ListBox1.Items.Add(OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "播放" Then
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Button2.Text = "暂停"
Else
AxWindowsMediaPlayer1.Ctlcontrols.play()
Button2.Text = "播放"
End If
End Sub
Private Sub 打开ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开ToolStripMenuItem.Click
Button1_Click(sender, e)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop() '停止
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = 0 '重新开始
AxWindowsMediaPlayer1.URL = ""
End Sub
Private Sub 打开目录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开目录ToolStripMenuItem.Click
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fi As IO.FileInfo
Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
Dim file As String
For Each fi In dir.GetFiles("*.mp3")
file = fi.FullName
ListBox1.Items.Add(file)
Next
End If
End Sub
Private Sub 关闭ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 关闭ToolStripMenuItem.Click
''关闭
If MessageBox.Show("请确定你要关闭吗?", "关闭", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
Close()
Else
Return
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
HScrollBar1.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
End Sub
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = HScrollBar1.Value
End Sub
Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
If ListBox1.Text < "" Then
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString
End If
End Sub
Private Sub 影音播放_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
这个当初我跟着网上做的,你看看不知道行不行
Public Class 影音播放
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.InitialDirectory = "F:\Music"
OpenFileDialog1.Filter = "mp3 文件(*.mp3)|*.mp3|CD音频文件(*.wav)|*.wav|" & "视频(*.asf)|*.asf|所有文件(*.*)|*.*"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
ListBox1.Items.Add(OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "播放" Then
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Button2.Text = "暂停"
Else
AxWindowsMediaPlayer1.Ctlcontrols.play()
Button2.Text = "播放"
End If
End Sub
Private Sub 打开ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开ToolStripMenuItem.Click
Button1_Click(sender, e)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop() '停止
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = 0 '重新开始
AxWindowsMediaPlayer1.URL = ""
End Sub
Private Sub 打开目录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开目录ToolStripMenuItem.Click
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fi As IO.FileInfo
Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
Dim file As String
For Each fi In dir.GetFiles("*.mp3")
file = fi.FullName
ListBox1.Items.Add(file)
Next
End If
End Sub
Private Sub 关闭ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 关闭ToolStripMenuItem.Click
''关闭
If MessageBox.Show("请确定你要关闭吗?", "关闭", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
Close()
Else
Return
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
HScrollBar1.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
End Sub
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition() = HScrollBar1.Value
End Sub
Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
If ListBox1.Text < "" Then
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString
End If
End Sub
Private Sub 影音播放_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
这个当初我跟着网上做的,你看看不知道行不行
展开全部
它默认不是自动播放哦,这样就可以了.已经测试过了.
Private Sub Command1_Click()
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) <> 0 Then
WindowsMediaPlayer1.settings.autoStart = True
WindowsMediaPlayer1.URL = CommonDialog1.FileName
End If
End Sub
Private Sub Command1_Click()
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) <> 0 Then
WindowsMediaPlayer1.settings.autoStart = True
WindowsMediaPlayer1.URL = CommonDialog1.FileName
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
该代码就是打开一个"打开文件"的窗口,你选择一个媒体文件后确定即可.
你也可以直接把文件路径加进去试试:
比如
WindowsMediaPlayer1.URL ="D:\我爱你.dat"
我爱你.dat是一个文件,你可以用你的文件替代,也可以是一首mp3,比如"D:\心跳-王力宏.mp3"
你也可以直接把文件路径加进去试试:
比如
WindowsMediaPlayer1.URL ="D:\我爱你.dat"
我爱你.dat是一个文件,你可以用你的文件替代,也可以是一首mp3,比如"D:\心跳-王力宏.mp3"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询