locked
I ask about AxWindowsPlayer tool: RRS feed

  • Question

  • I wonder how can I work program can play songs in a row but separated by a certain time?
    // 
    note that I want to create a program that can play one of song. when this song has stopped,the next song will play after 7 min Ex. and return to the first song. my question here is HOW IT WILL BE ?
    Thursday, January 16, 2014 12:28 PM

Answers

  • This code is for a dynamically added WMP. You will probably have to change the commands for a WMP placed on a Form from the toolbox.

    For this code you need to add the reference to WMPLib.dll, a button and timer to the Form also. And instead of AddSeconds you probably want to AddMinutes.

    Option Strict On
    
    ' Add reference, Project tab, add reference, Browse, C:\Windows\System32\wmp.dll
    Imports WMPLib
    
    Public Class Form1
    
        Dim Media As New List(Of String)
    
        Dim WithEvents AxWindowsMediaPlayer1 As New WMPLib.WindowsMediaPlayer
        Dim SomeMedia As WMPLib.IWMPMedia
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            AxWindowsMediaPlayer1.windowlessVideo = True
            AxWindowsMediaPlayer1.enableContextMenu = True
            Media.Add("C:\Users\John\Music\Phil_Collins_I_Dont_Care_Anymore.mp3") ' Playlist plays in reverse order from last added item to first added item.
            Media.Add("C:\Users\John\Music\Miami Vice Theme.mp3")
            For Each Item In Media
                SomeMedia = AxWindowsMediaPlayer1.newMedia(Item)
                AxWindowsMediaPlayer1.currentPlaylist.appendItem(SomeMedia)
            Next
            AxWindowsMediaPlayer1.settings.setMode("loop", True)
            Timer1.Interval = 500 ' Provides time for WMP to start before timer begins.
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            AxWindowsMediaPlayer1.controls.playItem(SomeMedia)
            Timer1.Start()
        End Sub
    
        Dim PauseTime As DateTime
        Dim IsPaused As Boolean = False
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            If IsPaused = False Then Timer1.Interval = 1
            ' Below comparison pauses song with 1 second left on it.
            If IsPaused = False AndAlso AxWindowsMediaPlayer1.controls.currentPosition.CompareTo(AxWindowsMediaPlayer1.currentMedia.duration - 1) = 1 Then
                PauseTime = DateTime.Now
                AxWindowsMediaPlayer1.controls.pause()
                IsPaused = True
                Timer1.Interval = 500
            End If
            If IsPaused = True Then
                If DateTime.Compare(PauseTime.AddSeconds(10), DateTime.Now) <= 0 Then
                    AxWindowsMediaPlayer1.controls.play() ' Start player then go to next song in playlist.
                    AxWindowsMediaPlayer1.controls.next()
                    IsPaused = False
                End If
            End If
    
        End Sub
    
    End Class
    


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    • Proposed as answer by IronRazerz Friday, January 17, 2014 4:15 AM
    • Marked as answer by Aladham Qwas Friday, January 17, 2014 7:47 PM
    Thursday, January 16, 2014 7:49 PM

All replies

  • I wonder how can I work program can play songs in a row but separated by a certain time?

    That depends if all the songs are to be separated by the same time or different times.

    You can pause and play the WMP at will. So if you detect a song has finished playing then pause it, use a timer for the pause interval then play the WMP for the next song in the playlist.

    If the songs are to be separated by different times then you possibly need separate playlists. One for each song. And then depending on the playlist name would depend on what to set the timer to start the WMP using a new playlist for the new song. As when the WMP ends playing a song that can be detected in an event handler I believe or at least by a seperate timer.

    Perhaps this event will tell if the AxWindowsMediaPlayer has finished playing a song.

    AxWindowsMediaPlayer.status property

    Also note that commands for the WMP are different for some reason between a WMP control dragged onto a form from the tool box or a dynamically created WMP that is not shown on the form.

    For example this is a command for a dynamically created AxWindowsMediaPlayer.

    AxWindowsMediaPlayer1.controls.currentPosition.ToString

    And this is the same command for an AxWindowsMediaPlayer control from the toolbox.

    AxWindowsMediaPlayer1.Ctlcontrols.currentPosition.ToString

    Not all commands are different.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.



    • Edited by Mr. Monkeyboy Thursday, January 16, 2014 2:37 PM 5555
    Thursday, January 16, 2014 2:17 PM
  • Thanks u for your nice answer :) note that I want to create a program that can play one of song. when this song has stopped,the next song will play after 7 min Ex. and return to the first song. my question here is HOW IT WILL BE ? :)
    Thursday, January 16, 2014 4:12 PM
  • This code is for a dynamically added WMP. You will probably have to change the commands for a WMP placed on a Form from the toolbox.

    For this code you need to add the reference to WMPLib.dll, a button and timer to the Form also. And instead of AddSeconds you probably want to AddMinutes.

    Option Strict On
    
    ' Add reference, Project tab, add reference, Browse, C:\Windows\System32\wmp.dll
    Imports WMPLib
    
    Public Class Form1
    
        Dim Media As New List(Of String)
    
        Dim WithEvents AxWindowsMediaPlayer1 As New WMPLib.WindowsMediaPlayer
        Dim SomeMedia As WMPLib.IWMPMedia
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            AxWindowsMediaPlayer1.windowlessVideo = True
            AxWindowsMediaPlayer1.enableContextMenu = True
            Media.Add("C:\Users\John\Music\Phil_Collins_I_Dont_Care_Anymore.mp3") ' Playlist plays in reverse order from last added item to first added item.
            Media.Add("C:\Users\John\Music\Miami Vice Theme.mp3")
            For Each Item In Media
                SomeMedia = AxWindowsMediaPlayer1.newMedia(Item)
                AxWindowsMediaPlayer1.currentPlaylist.appendItem(SomeMedia)
            Next
            AxWindowsMediaPlayer1.settings.setMode("loop", True)
            Timer1.Interval = 500 ' Provides time for WMP to start before timer begins.
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            AxWindowsMediaPlayer1.controls.playItem(SomeMedia)
            Timer1.Start()
        End Sub
    
        Dim PauseTime As DateTime
        Dim IsPaused As Boolean = False
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            If IsPaused = False Then Timer1.Interval = 1
            ' Below comparison pauses song with 1 second left on it.
            If IsPaused = False AndAlso AxWindowsMediaPlayer1.controls.currentPosition.CompareTo(AxWindowsMediaPlayer1.currentMedia.duration - 1) = 1 Then
                PauseTime = DateTime.Now
                AxWindowsMediaPlayer1.controls.pause()
                IsPaused = True
                Timer1.Interval = 500
            End If
            If IsPaused = True Then
                If DateTime.Compare(PauseTime.AddSeconds(10), DateTime.Now) <= 0 Then
                    AxWindowsMediaPlayer1.controls.play() ' Start player then go to next song in playlist.
                    AxWindowsMediaPlayer1.controls.next()
                    IsPaused = False
                End If
            End If
    
        End Sub
    
    End Class
    


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    • Proposed as answer by IronRazerz Friday, January 17, 2014 4:15 AM
    • Marked as answer by Aladham Qwas Friday, January 17, 2014 7:47 PM
    Thursday, January 16, 2014 7:49 PM
  • It was very helpful! thnks u very very muth!
    Now I wonder:
    How the songs are played at random ..? 
    Why stop the song before it is finished! 
    How can I hide the form to appear next to the clock ..?

    QQQ

    Friday, January 17, 2014 7:48 PM
  • It was very helpful! thnks u very very muth!
    Now I wonder:
    How the songs are played at random ..? 
    Why stop the song before it is finished! 
    How can I hide the form to appear next to the clock ..?

    QQQ

    You're supposed to begin a new thread for a new question.

    Change the word "loop" to the word "shuffle" to play songs randomly.

    The song is stopped before it finishes in order to pause the WMP before the song ends and WMP automatically begins playing the next song. Perhaps you can change 1 to 0.5 or 0.1 and see if that works. Typically songs have some period of time when they end and the track has nothing on it so I used 1 to equal 1 second.

    If you were hiding a Form why would it appear anywhere? If you want to display it minimized as an Icon next to the system clock then post a new question asking how to do that after you have done some research and learned the names of the areas in the taskbar you want to do this in and what you want done.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    Friday, January 17, 2014 11:10 PM
  • Thank you, you've helped me a lot. 
    Eventually I would like to ask you what are the best way to learn this language well ..?

    QQQ

    Saturday, January 18, 2014 12:50 PM