none
请问如何将ListBox中的文件加入AxWindowsMediaPlayer的播放列表??? RRS feed

  • 问题

  •  

    刚学的vs.net2008,才一个星期,很多东西都不懂,请不要见笑。

    我编了一个播放器,可是不能实现顺序播放,已经将目录内的媒体文件写入ListBox中,剩下的问题就如题了

    请高手指点 一下,先感谢了。

    2008年11月1日 23:46

答案

  • PlayStateChange事件里判段

    Code Snippet

    e.newState == WMPLib.WMPPlayState.wmppsReady

     

     

    如果是就表示以播放完毕可以播放下一个
    2008年11月2日 6:56
    版主
  • Code Snippet

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
           

    if e.newState = WMPLib.WMPPlayState.wmppsReady then

            AxWindowsMediaPlayer1.Ctlcontrols.play()

    end if


        End Sub

     

     

     

    2008年11月3日 3:48
    版主
  •  

     

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
                AxWindowsMediaPlayer1.URL = ListBox1.Items(index).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()

            End If

     

        End Sub

    2008年11月3日 9:45
    版主
  •  

    感谢老师指点,已经解决!


        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange

            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
                If ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1 Then
                    AxWindowsMediaPlayer1.Ctlcontrols.stop()
                Else

                    ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                    AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的

                    AxWindowsMediaPlayer1.Ctlcontrols.play()

                End If
            End If

     

        End Sub

    2008年11月3日 10:15

全部回复

  • 办法1,在每一个文件播放后,调用播放结束事件,读取下一个文件

    办法2,将ListBox里的文件临时创建出一个播放列表文件(格式请参照播放器的导出播放列表的格式或者参考asx的文档),播放这个列表文件即可自动连播

     

    2008年11月2日 2:03
    版主
  • 以下是我的文件:Public Class Form1
      

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            OpenFileDialog1.InitialDirectory = "e:\kugou"
            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 打开文件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

        End Sub

        Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
            AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString

        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         

        End Sub

        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            AxWindowsMediaPlayer1.URL = TextBox1.Text.ToString
        End Sub

     

        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            AxWindowsMediaPlayer1.currentPlaylist.appendItem(ListBox1.SelectedIndices)

            AxWindowsMediaPlayer1.Ctlcontrols.play()


        End Sub

       
        Private Sub ListBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.TextChanged
            AxWindowsMediaPlayer1.currentPlaylist.appendItem(ListBox1.SelectedIndices)
        End Sub
    End Class

     

    请帮忙看下应该如何改???。还是先谢谢了

     

     

    2008年11月2日 6:37
  • PlayStateChange事件里判段

    Code Snippet

    e.newState == WMPLib.WMPPlayState.wmppsReady

     

     

    如果是就表示以播放完毕可以播放下一个
    2008年11月2日 6:56
    版主
  •  

    感谢各位大大的回复,不过,我还是一菜菜

     

     

    目前还没有搞清大的概念,只知道一些简单的东西。

     

     

    能针对我的程序给改一下吗??

     

    因为要我自己去改我还没到那个水平!!

     

    正在努力学习中。。。。。。。。

     

    2008年11月2日 7:06
  • Code Snippet

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
           

    if e.newState = WMPLib.WMPPlayState.wmppsReady then

            AxWindowsMediaPlayer1.Ctlcontrols.play()

    end if


        End Sub

     

     

     

    2008年11月3日 3:48
    版主
  •  

    feiyun0112 老大,你好

    感谢你的回复

     

    首先如果加你的

     

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
           

    if e.newState = WMPLib.WMPPlayState.wmppsReady then

            AxWindowsMediaPlayer1.Ctlcontrols.play()

    end if


        End Sub

    则会没有反应,播放完后即停止

     

    如果改成

     

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
           

    if e.newState = WMPLib.WMPPlayState.wmppsStopped then

            AxWindowsMediaPlayer1.Ctlcontrols.play()

    end if


        End Sub

     

    则只能实现对单曲进行重复播放

     

    我现在的问题是:

        要把listbox1中的文件中的文件重新加载到axwindowsmediaplayer的播放列表中,并以listbox1的文件顺序来实现顺序播放

        请各位老师仔细看看,应该如果实现???

     

    下面是我的代码

     

    Public Class Form1
      

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            OpenFileDialog1.InitialDirectory = "e:\kugou"
            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 打开文件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 ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
            AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString

        End Sub

       

        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            AxWindowsMediaPlayer1.URL = TextBox1.Text.ToString
        End Sub

     

        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
              
                AxWindowsMediaPlayer1.Ctlcontrols.play()

            End If

     

        End Sub

      
    End Class

    2008年11月3日 9:41
  •  

     

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
                AxWindowsMediaPlayer1.URL = ListBox1.Items(index).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()

            End If

     

        End Sub

    2008年11月3日 9:45
    版主
  •  

    感谢老师指点,已经解决!


        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange

            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
                If ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1 Then
                    AxWindowsMediaPlayer1.Ctlcontrols.stop()
                Else

                    ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                    AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的

                    AxWindowsMediaPlayer1.Ctlcontrols.play()

                End If
            End If

     

        End Sub

    2008年11月3日 10:15
  •  

    继续问老师们,如何使AxWindowsMediaPlayer界面上的“上一曲”和“下一曲”图标有效???并通过点击能执行相应功能??
    2008年11月3日 11:41
  • Code Snippet

    '打开目录ToolStripMenuItem_Click

    dim pl as Microsoft.MediaPlayer.Interop.IWMPPlaylist

    pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist("playlistName")

    For Each fi In dir.GetFiles("*.mp3")
                    file = fi.FullName
                    ListBox1.Items.Add(file)

        dim m as Microsoft.MediaPlayer.Interop.IWMPMedia  = axWindowsMediaPlayer1.newMedia(file)       pl.appendItem(m);
                Next

    axWindowsMediaPlayer1.currentPlaylist = pl

     

     

    2008年11月5日 3:35
    版主
  • 是这样吗??老师,我总是搞不好!


        Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
            'Dim fi As IO.FileInfo
            ' Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
            'Dim file As String
            'Dim m As Microsoft.MediaPlayer.Interop.IWMPMedia = AxWindowsMediaPlayer1.newMedia(file)
            ' Dim pl As Microsoft.MediaPlayer.Interop.IWMPPlaylist

            ' pl = AxWindowsMediaPlayer1.playlistCollection.newPlaylist("playlistName")


            'For Each fi In dir.GetFiles("*.mp3")
            'file = fi.FullName
            ' ListBox1.Items.Add(file)

            'pl.appendItem(m)
            'Next
            'AxWindowsMediaPlayer1.currentPlaylist = pl

        End Sub

     

     

    这总是提示出错,麻烦再看一下

     

     

    这是我的全部代码

     

    做得基本差不多了:

     

    Public Class Form1


      
        Private Sub 打开文件ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开文件ToolStripMenuItem.Click
            OpenFileDialog1.InitialDirectory = "c:\"
            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 打开目录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 ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
            AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString
        End Sub
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            AxWindowsMediaPlayer1.URL = TextBox1.Text.ToString
        End Sub
        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
                If ListBox1.SelectedIndex = ListBox1.SelectedIndices.Count Then
                    AxWindowsMediaPlayer1.Ctlcontrols.stop()
                Else
                    ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                    AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的
                    AxWindowsMediaPlayer1.Ctlcontrols.play()
                End If
            End If
            Label3.Text = ListBox1.SelectedIndex & "/" & ListBox1.Items.Count - 1

        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            FolderBrowserDialog1.SelectedPath = "e:\kugou\"
            Dim fi As IO.FileInfo
            Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
            Dim file As String
            ListBox1.Items.Clear()

            For Each fi In dir.GetFiles("*.mp3")
                file = fi.FullName
                ListBox1.Items.Add(file)
            Next
            ListBox1.SelectedIndex = 0

     

        End Sub

        Private Sub 下一曲ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 下一曲ToolStripMenuItem.Click
            If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then
                ListBox1.SelectedIndex = 0
                AxWindowsMediaPlayer1.Ctlcontrols.play()

            Else
                ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If

        End Sub

        Private Sub 上一曲ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 上一曲ToolStripMenuItem.Click
            If ListBox1.SelectedIndex = 0 Then
                AxWindowsMediaPlayer1.Ctlcontrols.stop()
            Else
                ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If
        End Sub

        Private Sub 保存列表ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 保存列表ToolStripMenuItem.Click
           


        End Sub

        Private Sub 删除列表ToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles 删除列表ToolStripMenuItem.Click
            ListBox1.Items.Clear()

     

        End Sub

        Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
            'Dim fi As IO.FileInfo
            ' Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
            'Dim file As String
            'Dim m As Microsoft.MediaPlayer.Interop.IWMPMedia = AxWindowsMediaPlayer1.newMedia(file)
            ' Dim pl As Microsoft.MediaPlayer.Interop.IWMPPlaylist

            ' pl = AxWindowsMediaPlayer1.playlistCollection.newPlaylist("playlistName")


            'For Each fi In dir.GetFiles("*.mp3")
            'file = fi.FullName
            ' ListBox1.Items.Add(file)

            'pl.appendItem(m)
            'Next
            'AxWindowsMediaPlayer1.currentPlaylist = pl

        End Sub
    End Class

     

    在此,感谢两位老师先,真诚的

     

    2008年11月5日 4:30
  •  

    这是我的界面

     

    <img>http://ncat1.512j.com/11.jpg</img>
    2008年11月5日 4:39
  • Dim m As Microsoft.MediaPlayer.Interop.IWMPMedia

     

     ListBox1.Items.Add(file)

    m= AxWindowsMediaPlayer1.newMedia(file)

    pl.appendItem(m)

    2008年11月5日 4:53
    版主
  • 我要加在form1_load当中

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            FolderBrowserDialog1.SelectedPath = "e:\kugou\"
            Dim fi As IO.FileInfo
            Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
            Dim file As String

            ListBox1.Items.Clear()

            For Each fi In dir.GetFiles("*.mp3")
                file = fi.FullName
                ListBox1.Items.Add(file)
            Next
            ListBox1.SelectedIndex = 0

     

        End Sub

    请问如果改?

     

    您 上面的依然报错

     

    2008年11月5日 5:06
  •  

    我用的是VS 2008

     

    2008年11月5日 5:14
  •  

    代码 &  错误
    2008年11月6日 1:17
    版主
  • 按您说的加入代码后,程序为

    Private Sub 打开目录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开目录ToolStripMenuItem.Click
            Dim pl As Microsoft.MediaPlayer.Interop.IWMPPlaylist
            Dim m As Microsoft.MediaPlayer.Interop.IWMPMedia


            pl = AxWindowsMediaPlayer1.playlistCollection.newPlaylist("playlistName")

            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)
                    Dim m As Microsoft.MediaPlayer.Interop.IWMPMedia = AxWindowsMediaPlayer1.newMedia(file)
                    m = AxWindowsMediaPlayer1.newMedia(file)

                    pl.appendItem(m)


                Next
                AxWindowsMediaPlayer1.currentPlaylist = pl
            End If
        End Sub

    但出现如下错误,共4处

    1:

    未定义类型:“Microsoft.MediaPlayer.Interop.IWMPPlaylist”

    2:

    未定义类型:“Microsoft.MediaPlayer.Interop.IWMPMedia”

    3:

    变量m在封闭块中隐藏变量

    4:

    未定义类型:“Microsoft.MediaPlayer.Interop.IWMPMedia”

     

     

     

    我今天还发现一个问题,呵呵,不好意思,学习过程中。。。。。。

    为什么顺序播放时总是要跳过一首呢??就是说并不是接着播下一首,而是下第二首,晕了,又找不到VB.net的中文教材。。。。。。。。。。。。。。

    下面是我的全部代码

    Public Class Form1

     

        Private Sub 打开文件ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开文件ToolStripMenuItem.Click
            OpenFileDialog1.InitialDirectory = "c:\"
            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 打开目录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 ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
            ListBox1.SelectedIndex = ListBox1.SelectedIndex
            AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem.ToString

        End Sub
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            AxWindowsMediaPlayer1.URL = TextBox1.Text.ToString
        End Sub
        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If e.newState = WMPLib.WMPPlayState.wmppsStopped Then

                ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If

            Label3.Text = ListBox1.SelectedIndex & "/" & ListBox1.Items.Count - 1


        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            FolderBrowserDialog1.SelectedPath = "e:\kugou\"
            Dim fi As IO.FileInfo
            Dim dir As IO.DirectoryInfo = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
            Dim file As String


            ListBox1.Items.Clear()

            For Each fi In dir.GetFiles("*.mp3")
                file = fi.FullName
                ListBox1.Items.Add(file)

            Next
            ListBox1.SelectedIndex = 0

            AxWindowsMediaPlayer1.Ctlcontrols.play()


        End Sub

        Private Sub 下一曲ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 下一曲ToolStripMenuItem.Click
            If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then
                ListBox1.SelectedIndex = 0
                AxWindowsMediaPlayer1.Ctlcontrols.play()

            Else
                ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If

        End Sub

        Private Sub 上一曲ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 上一曲ToolStripMenuItem.Click
            If ListBox1.SelectedIndex = 0 Then
                AxWindowsMediaPlayer1.Ctlcontrols.stop()
            Else
                ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If
        End Sub

        Private Sub 保存列表ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 保存列表ToolStripMenuItem.Click
           


        End Sub

        Private Sub 删除列表ToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles 删除列表ToolStripMenuItem.Click
            ListBox1.Items.Clear()

     

        End Sub

     
    End Class

     

    2008年11月6日 7:00
  • 命名空间错了,你就用IWMPMedia 看看

     

    因该市点下一曲时也触发了PlayStateChange事件,你跟中应该可以发现

    可以加个全局变量判断

    Code Snippet

    dim blnClickBtn as boolean

     

     

     

    Code Snippet

      Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
            If not blnclickbtn and e.newState = WMPLib.WMPPlayState.wmppsStopped Then

                ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If

            Label3.Text = ListBox1.SelectedIndex & "/" & ListBox1.Items.Count - 1


        End Sub

     

     

     

    Private Sub 下一曲ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 下一曲ToolStripMenuItem.Click

    blnclickbtn =true
            If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then
                ListBox1.SelectedIndex = 0
                AxWindowsMediaPlayer1.Ctlcontrols.play()

            Else
                ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex).ToString 'index是你下一首的
                AxWindowsMediaPlayer1.Ctlcontrols.play()
            End If

    blnclickbtn =false

        End Sub

    2008年11月6日 7:26
    版主
  •  

    后一个问题,故障依然,呵呵
    2008年11月6日 7:55