4 Replies - 4234 Views - Last Post: 24 August 2012 - 07:09 AM Rate Topic: -----

#1 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Media Player Play Next Song

Posted 22 July 2011 - 06:19 PM

Hi All,
Im working on a media player for my work. It is suppose to be a song randomizer. I do have this mostly working. My issue is getting it to correctly switch songs when one ends. I just dont know why it is half working and half not. So my issue, after much debugging, which i have kept in my code i will post, i have found that when the song changes, the song does change, the index in the listbox goes up one and the 2nd song starts playing. I should note that i do have the code for playing the next song.....
WMPwindow.Ctlcontrols.play()

commented out, but the song still plays. The issue then is that after it steps into my if statement, it changes the song index, resets the song in the media player to the new one, it goes out of the if statement because the media player state has changed, it goes back through the media player state change event like 3 times skipping over the if statement, then the next time through it goes back into the if statement where it resets the variable "song", then it moves onto my msgbox for debugging purposes and that tells me the song playstate is a 9, which means its transitioning. When i close the msgbox, the music stops. There is no where in the media state change event that tells it to stop, the only place that tells it to stop is my custom stop button i added on there. Another confusing thing, i use this same exact code in my custom next song button (actually a picture) and it works fine. So in all what i wanted is that the song ends, the listbox index goes up one to highlight a new song and then that song plays. It does do that, but then it stops. So after my long winded message, here is my code where it gets messed up:
Private Sub WMPwindow_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles WMPwindow.PlayStateChange
        If WMPwindow.playState = WMPPlayState.wmppsMediaEnded Then
            SongsListBox.SelectedIndex = SongsListBox.SelectedIndex + 1
            song = "C:\Users\SamLemx\Desktop\Music\" & SongsListBox.SelectedItem.ToString
            WMPwindow.URL = song
            MsgBox(WMPwindow.playState)
            'WMPwindow.Ctlcontrols.play()
            If WMPwindow.playState = WMPPlayState.wmppsPlaying Then
                Exit Sub
            End If
        End If
    End Sub

Im hoping this is enough information for people to be able to help. Thanks everyone.

Sam

Is This A Good Question/Topic? 0
  • +

Replies To: Media Player Play Next Song

#2 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Media Player Play Next Song

Posted 03 August 2011 - 06:42 PM

Anything guys? It seems like the msgbox on line 6 is actually what plays the song. I changed it up some, it pops up the msgbox to say where the play state is at and then the music starts playing. This is before my code where i tell it to play. I put a break in at the if play state is transitioning and when it comes to that break the song is playing. The issue is that when i step into it and get all the way stepped through, the music stops. Ive tried everything i could think of! i am using a WMP control. Heres my code for that part now:
Private Sub WMPWindow_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles WMPwindow.PlayStateChange
        If WMPwindow.playState = WMPLib.WMPPlayState.wmppsMediaEnded Then
            SongsListBox.SelectedIndex = SongsListBox.SelectedIndex + 1
            WMPwindow.URL = "C:\Users\SamLemx\Desktop\Music\" & SongsListBox.SelectedItem.ToString
            MsgBox(WMPwindow.playState)

            If WMPwindow.playState = WMPLib.WMPPlayState.wmppsTransitioning Then
                If WMPwindow.playState = WMPLib.WMPPlayState.wmppsReady Then

                    WMPwindow.Ctlcontrols.play()
                    Exit Sub
                
                End If
            End If
        End If
        
    End Sub

It is very basic for that part but it doesnt work right. I appreciate any help guys.

Thanks,
Sam
Was This Post Helpful? 0
  • +
  • -

#3 Moogoo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 80
  • Joined: 06-January 10

Re: Media Player Play Next Song

Posted 22 August 2012 - 12:20 PM

Hey, I know this about a year too late, but for anyone looking up this section of code, here is a solution for you:
Private Sub WMPWindow_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles WMPwindow.PlayStateChange  

        Static Dim PlayMe As Boolean = True
        Select Case WMPwindow.playState
            Case 10
                If PlayMe Then
                    WMPwindow.Ctlcontrols.play()
                End If
            Case 8
                If SongsListBox.SelectedIndex = SongsListBox.Items.Count - 1 Then
                    PlayMe = False
                Else

                    SongsListBox.SelectedIndex = SongsListBox.SelectedIndex + 1
                    PlayMe = False
                    WMPwindow.URL = "C:\Users\SamLemx\Desktop\Music\" & SongsListBox.SelectedItem.ToString 
                    WMPwindow.Ctlcontrols.play()
                    PlayMe = True
                End If
        End Select
   End Sub 




This will handle the PlayStateChanges that happen, and there are a few between each song (7!). I'm sorry this probably doesn't help the original requestor, but hopefully it's useful to someone in the future!!
Was This Post Helpful? 0
  • +
  • -

#4 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Media Player Play Next Song

Posted 22 August 2012 - 04:57 PM

doesnt help the original poster but thats ok cuz i had figured it out a long time ago! haha my code does a lot more than just play a song though, it loops thru some subs, checks this and that and something else, works with a text file and so on haha i figured if i pasted that it would just confuse people :D

Sam
Was This Post Helpful? 0
  • +
  • -

#5 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 920
  • Joined: 09-May 09

Re: Media Player Play Next Song

Posted 24 August 2012 - 07:09 AM

approah was a little unusual

id . . .

1. find all the .mp3 files in a directory and list there names in a listview
2. store there directories in an array
3. get the selected index of the mp3 clicked in the listview
4. use that index to get the file path of the mp3 from the array
5. url = directlylist(index)

Simples . . .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1