TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

how to Automatically select next item in listbox

VB.NET


Reply
 
Thread Tools Display Modes
Old 29-10-2007, 05:31 AM   #11
Clarence
Guest
 
Posts: n/a
RE: how to Automatically select next item in listbox

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

Posted via DevelopmentNow.com Groups

  Reply With Quote
Old 07-12-2007, 07:21 PM   #12
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 07-12-2007, 07:21 PM   #13
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 07-12-2007, 07:21 PM   #14
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 07-12-2007, 07:28 PM   #15
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 07-12-2007, 07:37 PM   #16
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 07-12-2007, 07:52 PM   #17
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 07-12-2007, 07:53 PM   #18
Jerry Spence1
Guest
 
Posts: n/a
Re: how to Automatically select next item in listbox

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




"Lim Eng Keong" <> wrote in message
news:.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <> wrote in message
> news:...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>



  Reply With Quote
Old 31-10-2008, 09:29 PM   #19
Newbie
 
Join Date: Oct 2008
Age: 17
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 M0rPh3n3 is an unknown quantity at this point
Thumbs up Re: how to Automatically select next item in listbox

Quote:
Originally Posted by Jerry Spence1 View Post
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




"Lim Eng Keong" <admin@infoct.net> wrote in message
news:OWBdIRoCIHA.5712@TK2MSFTNGP05.phx.gbl...
> Use timer maybe?
>
> "Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
> news:86C3A9B2-49D2-4058-9698-52D90BBB586F@microsoft.com...
>> Then use that button click and place a label before it, "Next to play".
>>
>> Cor

>
I Myself also created a media Player and struggled with the same problem as the first post but i have used your solution Jerry and it works fin except for the axmediaplayer that should play the selected sings Each time it selects the item but the media layer merely says "opening file" and doesnt play the file Do u know how to fix this problem?

any help is appreciated

M0rPh3n3
M0rPh3n3 is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Persistent Menu Item Stays on Screen After I Select it Jacob Sorensen Windows Vista All 5 04-01-2009 01:50 AM
Display multi line text as one item in a listbox ashwath C#(C Sharp) 2 18-09-2007 01:36 AM
ListBox vs GridBox darien.watkins@gmail.com VB.NET 1 15-09-2007 11:36 AM
unable to select options from a SELECT control Abhishek Tiwari Internet Explorer 1 28-08-2007 08:42 PM
unable to select options from a SELECT control Abhishek Tiwari Internet Explorer 1 28-08-2007 08:38 PM


< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 03:04 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional