怎么使用在VB中添加的windows media player 9.0的播放控件呢?

Alice 2004-04-02 09:49:05
怎么使用在VB中添加的windows media player 9.0的播放控件呢?
哪个事件方法是打开一个播放文件呢?怎么我可以动态的写播放文件呢?
谁有DEMO,给我发一个好吗?急呀!!可以mail to :hanbd@163.net
...全文
432 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsftest 2004-07-17
  • 打赏
  • 举报
回复
哪个事件方法是打开一个播放文件呢?怎么我可以动态的写播放文件呢?
========================]
直接设定url就可以播放了,简单例子:

Private Sub Command1_Click()
WindowsMediaPlayer1.URL = "E:\ABC.MP3"
End Sub

webmasterss 2004-07-17
  • 打赏
  • 举报
回复
你去找,有个源码叫 东方播放器,写的很精彩
BlueBeer 2004-07-17
  • 打赏
  • 举报
回复
简单的不能再简单的例子


Private Sub Form_Resize()
WMP.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub

Private Sub mnuOpen_Click()
With CommonDialog1
.FileName = ""
.Filter = "支持的常见格式|*.mp3;*.wav;*.mid;*.cda;*.avi;*.mpg;*.mpeg;*.dat;*.m3u;*.asf;*.asx;*.wma;*.wmv|所有文件(*.*)|*.*"
.ShowOpen
If Len(.FileName) Then WMP.URL = .FileName
End With
End Sub

Private Sub munFull_Click()
On Error GoTo Err
WMP.fullScreen = True
Err:
End Sub
haowg 2004-07-17
  • 打赏
  • 举报
回复
陈老大,你给的是9.0的用法吗?我怎么看着不像啊
Alice 2004-04-02
  • 打赏
  • 举报
回复
我找了Meida Player没有file name 属性没有MediaPlay.FileName =c:\test.mp3
好像是文件名要在MeidaPlayer.url中写吧,MeidaPlayer.url=c:\test.mp3我试过了。
给我一个DEMO吧!!
华芸智森 2004-04-02
  • 打赏
  • 举报
回复
Option Explicit

Dim DltValue As Single
Dim SourMax As Long
Dim ImaT(10) As Long
Dim DltVolue As Single
Dim PlayFile As String
Dim SelFile As String
Dim SourVolue As Long
'---------------------------
Dim MediaLen As Long
Dim ListID As Long
Dim ListMax As Long
Dim DltLen As Single
Public FShow As Boolean
Dim StarPlay As Boolean

Private Sub FolserSel_FolderClick(Folder As CCRPFolderTV6.Folder, Location As CCRPFolderTV6.ftvHitTestConstants)
Dim Fpath As String
Dim a As Long
Dim TmpMax As Long

On Error Resume Next

Fpath = Folder.Name
If Mid$(Fpath, 2, 1) = ":" Then
If Right$(Fpath, 1) <> "\" Then Fpath = Fpath & "\"
If UCase$(Fpath) <> UCase$(List1.Tag) Then
File1.Path = Fpath: File1.Refresh: DoEvents
TmpMax = File1.ListCount - 1
If TmpMax > 0 Then
ListMax = TmpMax: List1.Visible = False: List1.Clear
For a = 0 To ListMax
List1.AddItem File1.List(a)
Next
List1.Visible = True: DoEvents
MediaLen = 99999: List1.Tag = Fpath
ListID = 0

SelFile = List1.List(ListID)
List1.ListIndex = ListID: Label4.Width = 15
Me.Caption = SelFile
MediaPlay.FileName = List1.Tag & SelFile
MediaPlay.Play
MediaLen = MediaPlay.SelectionEnd
DltLen = (Label3.Width - 30) / MediaLen
Timer1.Enabled = True
End If
End If
End If
End Sub

Private Sub Form_Load()
Dim a As Long
Dim ImaMax As Long
Dim Fpath As String

On Error Resume Next

Screen.MousePointer = 11
BkSourPlay.Hide
If P_TopWin Then TopWindow Me.hWnd
P_Lsound = True:
FShow = False
ImaMax = Image2.Count - 1

For a = 0 To ImaMax
ImaT(a) = Image2(a).Top
Next
Fpath = P_StarPath
MediaLen = 99999
File1.Pattern = P_Pattern

If Dir$(Fpath, vbDirectory + vbHidden) <> "" Then
If Right$(Fpath, 1) <> "\" Then Fpath = Fpath & "\"
FolserSel.SelectedFolder = Fpath
ListID = 0: File1.Path = Fpath
DoEvents: ListMax = File1.ListCount - 1
If ListMax > 0 Then
List1.Clear
For a = 0 To ListMax
List1.AddItem File1.List(a)
Next
List1.Tag = Fpath
End If
End If
MediaPlay.DisplayMode = mpTime
SourMax = -3000: SourVolue = -500
DltVolue = Image1.Width / (-SourMax / 100)
MediaPlay.Volume = SourVolue
Label1.Width = Image1.Width - (SourMax / SourVolue) * DltVolue
Screen.MousePointer = 0
BkSourPlay.Visible = True
End Sub


Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next

SaveSetting "SMBACKAUDIOPLAY", "AUDIOPLAY", "SM" & UCase$(App.EXEName) & "MEDIAPATH", BkSourPlay.FolserSel.SelectedFolder

MediaPlay.Stop
Timer1.Enabled = False
P_Lsound = False
End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim K As Long
Label1.Width = X
If X <= 60 Then
K = -5500
Else
K = (X - Image1.Width) * 100 / DltVolue
If K > 0 Then K = 0
End If
MediaPlay.Volume = K
End Sub

Private Sub Image2_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Image2(Index).Top = ImaT(Index) + 8
End Sub


Private Sub Image2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Dim Fpath As String
Dim SelStr As String
Dim ML As Long, MW As Long
Dim a As Long
Dim Spath As String
Dim Ppath As String

On Error Resume Next

Image2(Index).Top = ImaT(Index)
SelStr = Image2(Index).Tag
Select Case SelStr
Case Is = "播放"
SelFile = Trim$(List1.List(ListID))
If Len(SelFile) > 0 Then
Timer1.Enabled = False
MediaLen = 99999
List1.ListIndex = ListID
Me.Caption = SelFile
MediaPlay.FileName = List1.Tag & SelFile
MediaPlay.Play
MediaLen = MediaPlay.SelectionEnd
DltLen = (Label3.Width - 30) / MediaLen
Timer1.Enabled = True
End If
Case Is = "停止"
MediaPlay.Stop
Timer1.Enabled = False
Case Is = "文件"
ML = Me.Left: MW = Me.Width
FShow = Not FShow
If FShow Then
Spath = List1.Tag
If Dir(Spath, vbDirectory) <> "" Then
Ppath = FolserSel.SelectedFolder
If Right$(Ppath, 1) <> "\" Then Ppath = Ppath & "\"
If UCase$(Ppath) <> UCase$(Spath) Then
FolserSel.SelectedFolder = Spath
End If
End If
Me.Left = ML
Me.Width = 5745
Else
Me.Left = ML
Me.Width = 2970
End If
Case Is = "退出"
BkSourPlay.Visible = False
End Select
End Sub

Private Sub Label3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If DltLen > 0 Then
Label4.Width = X
MediaPlay.CurrentPosition = X / DltLen
End If
End Sub

Private Sub List1_Click()
ListID = List1.ListIndex
SelFile = List1.List(ListID)
End Sub

Private Sub List1_DblClick()
On Error Resume Next
If Len(SelFile) > 0 Then
MediaPlay.Stop
Me.Caption = SelFile
MediaPlay.FileName = List1.Tag & SelFile
Label4.Width = 15
MediaPlay.Play
MediaLen = MediaPlay.SelectionEnd
DltLen = (Label3.Width - 30) / MediaLen
Timer1.Enabled = True
End If
End Sub

Private Sub Timer1_Timer()
Dim CurTime As Long
Dim Lwidth As Long
Static OleTime As Long

On Error Resume Next

CurTime = MediaPlay.CurrentPosition
If OleTime <> CurTime Then Label4.Width = 15 + CurTime * DltLen: OleTime = CurTime
If CurTime >= (MediaLen - 0.5) And ListMax > 0 Then
ListID = ListID + 1
If ListID > ListMax Then ListID = 0
SelFile = List1.List(ListID)
If Len(SelFile) > 0 Then
List1.ListIndex = ListID
Label4.Width = 15
Me.Caption = SelFile
MediaPlay.FileName = List1.Tag & SelFile
MediaPlay.Play
MediaLen = MediaPlay.SelectionEnd
DltLen = (Label3.Width - 30) / MediaLen
End If
End If
End Sub
华芸智森 2004-04-02
  • 打赏
  • 举报
回复
CTRL+T==>WINDOWS MEDIA PLAYER
'***********************************
例如:

Public Function ShowPlay(Optional StarPath As String = "", Optional TopWin As Boolean = False, Optional Pattern As String = "*.MP3;*.WAV;*.MID;*.WMA;*.MPA;*.MP2;*.MP1;*.MPG;*.DAT")

On Error Resume Next

If Len(Trim$(StarPath)) = 0 Then
StarPath = GetSetting("SMBACKAUDIOPLAY", "AUDIOPLAY", "SM" & UCase$(App.EXEName) & "MEDIAPATH", "C:\")
End If
If Len(Trim$(Pattern)) = 0 Then Pattern = "*.MP3;*.WAV;*.MID;*.WMA;*.MPA;*.MP2;*.MP1;*.MPG;*.DAT"
P_Pattern = Pattern
P_StarPath = StarPath
P_TopWin = TopWin
BkSourPlay.Show
End Function

Public Function StopPlay() As Boolean

On Error Resume Next

If P_Lsound Then
BkSourPlay.MediaPlay.Stop
Unload BkSourPlay
Set BkSourPlay = Nothing
End If
Err.Clear
End Function
online 2004-04-02
  • 打赏
  • 举报
回复
你放一个对话框控件即可
Private Sub Form_Load()
MediaPlayer1.FileName = CommonDialog1.FileName
MediaPlayer1.Play
End Sub
solol 2004-04-02
  • 打赏
  • 举报
回复
你装一个windows media player 9.0,就可以加入这个控件了
9。0的事件方法与6.4有许多不同,建议你去微软下一个media player 9.0 sdk,里面有帮助文档
mycoldboy 2004-04-02
  • 打赏
  • 举报
回复
看看他的filename,url,play,stop等函数就明白了

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧