怎么使用在VB中添加的windows media player 9.0的播放控件呢?
哪个事件方法是打开一个播放文件呢?怎么我可以动态的写播放文件呢?
谁有DEMO,给我发一个好吗?急呀!!可以mail to :[email protected]

解决方案 »

  1.   

    你装一个windows media player 9.0,就可以加入这个控件了
    9。0的事件方法与6.4有许多不同,建议你去微软下一个media player 9.0 sdk,里面有帮助文档
      

  2.   

    你放一个对话框控件即可
    Private Sub Form_Load()
    MediaPlayer1.FileName = CommonDialog1.FileName
    MediaPlayer1.Play
    End Sub
      

  3.   

    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 FunctionPublic 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
      

  4.   

    Option ExplicitDim 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 BooleanPrivate 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 SubPrivate 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 SubPrivate 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 SubPrivate 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 SubPrivate 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 SubPrivate Sub List1_Click()
      ListID = List1.ListIndex
      SelFile = List1.List(ListID)
    End SubPrivate 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 SubPrivate 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
      

  5.   

    我找了Meida Player没有file name 属性没有MediaPlay.FileName =c:\test.mp3
    好像是文件名要在MeidaPlayer.url中写吧,MeidaPlayer.url=c:\test.mp3我试过了。
    给我一个DEMO吧!!
      

  6.   

    看看他的filename,url,play,stop等函数就明白了
      

  7.   

    简单的不能再简单的例子
    Private Sub Form_Resize()
    WMP.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
    End SubPrivate 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 SubPrivate Sub munFull_Click()
    On Error GoTo Err
    WMP.fullScreen = True
    Err:
    End Sub
      

  8.   

    哪个事件方法是打开一个播放文件呢?怎么我可以动态的写播放文件呢?
    ========================]
    直接设定url就可以播放了,简单例子:Private Sub Command1_Click()
    WindowsMediaPlayer1.URL = "E:\ABC.MP3"
    End Sub