紧急求助:vb做视频播放器
我做了一个视频播放器,用vb中的MediaPlayer,来播放avi等文件,出现了一个错误,就是文件没有加载到MediaPlayer中,看不到图像也没有声音,请各位高手给我看看哪里出现的问题,万分感谢!!!
Dim Flname As String
Dim Paus As Boolean
Dim hh As Integer, mm As Integer, ss As Integer
Private Sub Form_Load()
Form2.Width = Screen.Width / 2
Form2.Height = Screen.Height / 2
MediaPlayer1.Width = Screen.Width / 2 - 600
MediaPlayer1.Height = Screen.Height / 2 - 800
Label1.Caption = "00:00:00"
Label1.Left = MediaPlayer1.Left + MediaPlayer1.Width - Label1.Width - 900
Label1.Top = MediaPlayer1.Top + MediaPlayer1.Height - 266
Timer1.Interval = 1000
Paus = False
hh = 0
mm = 0
ss = 0
Timer1.Enabled = True
End Sub
Private Sub MediaPlayer1_PlayStateChange(ByVal NewState As Long)
If NewState = mpStopped Then
Timer1.Enabled = False
End If
If NewState = mpPaused Then
Timer1.Enabled = False
Paus = True
End If
If NewState = mpPlaying Then
If Paus = False Then
hh = 0
ss = 0
mm = 0
Else
Paus = False
End If
Timer1.Enabled = True
End If
If MediaPlayer1.AutoRewind = True Then
MediaPlayer1.Play
End If
End Sub
Private Sub mnucicl_Click()
If mnucicl.Checked = True Then
mnucicl.Checked = False
MediaPlay1.AutoRewind = False
Else
mnucicl.Checked = True
MediaPlayer1.AutoRewind = True
End If
End Sub
Private Sub mnuexit_Click()
End
End Sub
Private Sub mnufull_Click()
Form2.Left = 0
Form2.Top = 0
Form2.Width = Screen.Width
Form2.Height = Screen.Height
MediaPlayer1.Width = Screen.Width - 600
MediaPlayer1.Height = Screen.Height - 1000
Label1.Left = MediaPlayer1.Left + MediaPlayer1.Width - Label1.Width - 1200
Label1.Top = MediaPlayer1.Top + MediaPlayer1.Height - 266
End Sub
Private Sub mnunormal_Click()
Form2.Width = Screen.Width / 2
Form2.Height = Screen.Height / 2
MediaPlayer1.Width = Screen.Width / 2 - 600
MediaPlayer1.Height = Screen.Height / 2 - 800
Label1.Left = MediaPlayer1.Left + MediaPlayer1.Width - Label1.Width - 900
Label1.Top = MediaPlayer1.Top + MediaPlayer1.Height - 266
End Sub
Private Sub mnuopen_Click()
CommonDialog1.Filter = "Wmv文件|*.wmv|Wav文件|*.wav|MIDI文件|*.mid|AVI文件|*.avi|所有文件|*.*"
On Error Resume Next
CommonDialog1.ShowOpen
Flname = CommonDialog1.FileName
MediaPlayer1.FileName = Flname
hh = 0
mm = 0
ss = 0
Timer1.Enabled = True
End Sub
Private Sub mnuautst_click()
End Sub
Private Sub mnustart_Click()
If mnustart.Checked = True Then
mnustart.Checked = False
MediaPlayer1.autoStart = False
Else
mnuautst.Checked = True
MediaPlayer1.autoStart = True
End If
End Sub
Private Sub Timer1_Timer()
ss = ss + 1
If ss >= 60 Then
mm = mm + 1
ss = 0
If mm >= 60 Then
hh = hh + 1
mm = 0
End If
End If
Label1.Caption = Format$(hh, "00") & ":" & Format$(mm, "00") & ":" & Format$(ss, "00")
End Sub
[解决办法]
MediaPlayer1.FileName = Flname
把这句改成MediaPlayer1.url=Flname 就可以了