how to Automatically select next item in listbox

K

kimiraikkonen

Hello,
I have a moodest mp3 player which has a playlist as listbox1 which
shows full path or each inserted file.

The problem is, when a media playing is ended, i want my listbox to
select automatically next (under/below) item to continue.

What things can i add to that code:

If Me.AxWindowsMediaPlayer1.playState =
WMPLib.WMPPlayState.wmppsMediaEnded Then


End if
 
R

rowe_newsgroups

Hello,
I have a moodest mp3 player which has a playlist as listbox1 which
shows full path or each inserted file.

The problem is, when a media playing is ended, i want my listbox to
select automatically next (under/below) item to continue.

What things can i add to that code:

If Me.AxWindowsMediaPlayer1.playState =
WMPLib.WMPPlayState.wmppsMediaEnded Then

End if

Shouldn't it be:

Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1

You might want to do an if..then test to make sure you aren't at the
end of the List however.

Thanks,

Seth Rowe
 
K

kimiraikkonen

Shouldn't it be:

Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1

You might want to do an if..then test to make sure you aren't at the
end of the List however.

Thanks,

Seth Rowe

Hi Seth Rowe,
Great it worked for selection next item, but i couldn't make out how
to automatize. Which event or action can it be assigned to?

If the playing media is stopped due to end of stream:

If Me.AxWindowsMediaPlayer1.playState =
WMPLib.WMPPlayState.wmppsMediaStopped Then
Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1

That code works for a button click action for example, but i want to
automatize selecting next item, without needing to user prompt or user
mouse action. (Like in Windows Media Player's playlist, Winamp's
playlist)
 
C

Cor Ligthert[MVP]

kimiraikkonen,

You need an event from your mediaplayer for this which then can be handled.

Have a look in intelisense of the mediaplayer which there are.

Cor
 
K

kimiraikkonen

kimiraikkonen,

You need an event from your mediaplayer for this which then can be handled.

Have a look in intelisense of the mediaplayer which there are.

Cor

"kimiraikkonen" <[email protected]> schreef in bericht









- Show quoted text -

Hi,
I looked avaible events with the help of intellisense but only
AxWindowsMediaPlayer1.enter seems valid, but it does not produce
automatize which i want. But a button click does what i wanted if you
assign button1.click action but, as i said i don't want any user
action as normal.

Thanks for the interest.
 
R

rowe_newsgroups

Hi,
I looked avaible events with the help of intellisense but only
AxWindowsMediaPlayer1.enter seems valid, but it does not produce
automatize which i want. But a button click does what i wanted if you
assign button1.click action but, as i said i don't want any user
action as normal.

Thanks for the interest.

Hmm... unfortunately I've never to to use the AxWindowsMediaPlayer
active X object so I can't tell you what event to subscribe to. You
might go through the Object Browser and see if you can find any other
events or possible a field or property you can poll to find when it's
finished playing.

Thanks,

Seth Rowe
 
C

Cor Ligthert[MVP]

Then use that button click and place a label before it, "Next to play".

Cor
 
K

kimiraikkonen

Then use that button click and place a label before it, "Next to play".

Cor

But everytime song finishes, user is forced to click next button to go
to next selected song. I want it automatic. Possible?
 
A

Armin Zingler

kimiraikkonen said:
But everytime song finishes, user is forced to click next button to
go to next selected song. I want it automatic. Possible?

As Cor and Seth said, if there is no event available, it is not possible
automatically.

You could add a Timer and check the state in it's Tick event. If it is
ended, select the next item (as shown).


Armin
 
C

Clarence

Imports WMPLib
Imports System.Web.UI
Imports System.Diagnostics
Imports System
Imports System.Collections.Generic
Imports System.IO


Partial Class cpgFullCDSytes
Inherits System.Web.UI.Page

Public WithEvents wmpPlayer As WindowsMediaPlayer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
' MsgBox("Page_Load()")

'Create Player
wmpPlayer = New WMPLib.WindowsMediaPlayer()

'Configure Media Player Here
wmpPlayer.uiMode = "mini"


'Save the reference to Media Player To a session variable
Session.Add("MediaPlayer", wmpPlayer)

Dim lstItem As New ListItem
lstItem.Text = "PlayList"
lstItem.Value = -1
lstPlayList.Items.Add(lstItem)
lstPlayList.SelectedIndex = 0
lstPlayList.SelectionMode = ListSelectionMode.Single
lstPlayList.ControlStyle.BackColor = Drawing.Color.AntiqueWhite
Else
'MsgBox("Page.IsPostBack")

'Get a reference To Our Media Player Object Stored As a Session Value
wmpPlayer = Session.Item("Mediaplayer")
End If
End Sub

Protected Sub wmpPlayer_StatusChange() Handles wmpPlayer.StatusChange
' MsgBox(wmpPlayer.status)
If wmpPlayer.status = "Finished" Then
MsgBox("StatusChange: Finished")
End if
End Sub

Protected Sub wmpPlayer_PlayStateChange(ByVal newState As Int32) Handles wmpPlayer.PlayStateChange

If newState = WMPLib.WMPPlayState.wmppsMediaEnded Then
MsgBox("PlayStateChange: Media Ended")
End If
End Sub



Protected Sub btnPlay_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnPlay.Click
MsgBox("PlayButton")
If lstPlayList.Items.Count > 0 And lstPlayList.SelectedValue = "-1" Then
lstPlayList.SelectedIndex = 1
End If
'wmpPlayer.URL = "wma/3 Doors Down - The Better Life\1 - Kryptonite.wma"
wmpPlayer.URL = "wma/" & lstPlayList.SelectedValue
MsgBox("btnPlay_click - Media Player URL = " & wmpPlayer.URL)


End Sub
End Class

Hey, I am working on a similar project.
Porting my site http://FullCd.Sytes.Net to asp .net.

This code sniplet handles the media player events, but the events(PlayStateChange & StatusChange) seem to fire off 5 or 6 times for some strange reason, and I do not know ghow to sink these(possibly removeHandler() ). Also I had to use a Session Variable to store the Media Player Object Reference otherwise it loses itself. Please add a reference to WMPLib.dll to the vs2005 project

From http://www.developmentnow.com/g/38_...-Automatically-select-next-item-in-listbox.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
J

Jerry Spence1

If I've understood correctly I would have thought the following should do
the trick:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

Dim Filename As String = ListBox1.SelectedItem
AxWindowsMediaPlayer1.URL = Filename
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub

Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object,
ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles
AxWindowsMediaPlayer1.PlayStateChange
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded
Then
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
Else

'Start at the top of the list again if needed

ListBox1.SelectedIndex = 0

End If

End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top