Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Changing selection on a listbox


Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2005, 01:41 PM
Deckstruction Deckstruction is offline
Newcomer
 
Join Date: Nov 2004
Location: Essex, UK
Posts: 14
Default Changing selection on a listbox


I'm still messing around trying to get the WMP component working with playlists, as this doesnt seem to be feasible now I decided just to add files to a listbox.

I've got it so that double-clicking the list item makes WMP set the source URL to the path/filename clicked in the list, is there a way to automatically select the next item in a list, like as if i'd pressed the down cursor key or clicked the next item, i can use the end of audio stream event to trigger the start of the next track but i've no idea how to make the next item in the list become selected.

Also, is there a way i can store lists under a filename and recall them later? so it works in a way like a playlist editor, so i can load/save the contents of lists under different filenames?


Thanks
Reply With Quote
  #2  
Old 04-21-2005, 01:50 PM
stevo stevo is offline
Senior Contributor

* Expert *
 
Join Date: May 2004
Location: Manchester, England.
Posts: 1,254
Default

if you know when the song as finished then you need to just add 1 to the listindex, something like this
Code:
If List1.ListIndex < List1.ListCount - 1 Then List1.ListIndex = List1.ListIndex + 1 'play next song here End If
as for saving to file, have a look in tutors corner, there is a good FILE I/O tutorial by Gavino.
Reply With Quote
  #3  
Old 04-22-2005, 08:32 AM
Deckstruction Deckstruction is offline
Newcomer
 
Join Date: Nov 2004
Location: Essex, UK
Posts: 14
Default

Thanks Stevo,

I got a small problem now tho, it did seem to work OK for a bit but now it's advancing two items in the list. here's my code just wondering if you could have a look to see if you could see anything obviously wrong?

Code:
Private donealready As Boolean Private playing As Boolean Private paused As Boolean Private iclickedSTOP As Boolean _____________________________________________________________ Private Sub btnNext_Click() Call AdvanceMedia 'advance list to next track End Sub Private Sub btnPrevious_Click() If iclickedSTOP Then GoTo Skip If List1.ListIndex < List1.ListCount - 1 Then List1.ListIndex = List1.ListIndex - 1 End If If List1.Text <> "" Or List1.Text <> "c:\media" Then Call Stopped Skip: End Sub Private Sub btnStop_Click() iclickedSTOP = True WindowsMediaPlayer1.Controls.stop playpause.Caption = "PLAY" End Sub Private Sub cmdAddTrack_Click() List1.AddItem (File1.Path & "\" & File1.FileName) End Sub Private Sub Form_Load() File1.Path = "c:\media" List1.ListIndex = -1 If WindowsMediaPlayer1.playState = wmppsPlaying Then playing = True If WindowsMediaPlayer1.playState = paused Then paused = True End Sub Private Sub List1_Click() WindowsMediaPlayer1.URL = (List1.Text) End Sub Private Sub playpause_Click() If WindowsMediaPlayer1.playState = wmppsPlaying Then WindowsMediaPlayer1.Controls.pause Else WindowsMediaPlayer1.Controls.play If WindowsMediaPlayer1.playState = wmppsPlaying Then playpause.Caption = "PAUSE" Else playpause.Caption = "PLAY" If WindowsMediaPlayer1.playState = wmppsPlaying Then iclickedSTOP = False End Sub Private Sub Timer1_Timer() Timer1.Enabled = False WindowsMediaPlayer1.Controls.play End Sub Private Sub Stopped() WindowsMediaPlayer1.URL = (List1.Text) Timer1.Enabled = True Do While WindowsMediaPlayer1.playState = wmppsStopped Loop donealready = False End Sub Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long) If WindowsMediaPlayer1.playState = wmppsStopped Then Call AdvanceMedia End Sub Private Sub AdvanceMedia() If iclickedSTOP Then GoTo Skip If donealready = True Then GoTo Skip If List1.ListIndex < List1.ListCount - 1 Then List1.ListIndex = List1.ListIndex + 1 donealready = True End If If List1.Text <> "" Or List1.Text <> "c:\media" Then Call Stopped Skip: End Sub

I cant quite put my finger on whats causing that because one minute it was working, nothing was changed then it started avancing in two's but only when it reached the end of a song, if i click on the NEXT button it moves to the next track in the list, also i altered that code you posted to allow the PREVIOUS button to go backwards through the list, if it reaches the last track it wont allow me to go backwards, is there a way to do that or when it it's played the last item then revert back to the 1st item or similar as i'm nove never used the listindex or listcount instructions before

Thanks

Last edited by Deckstruction; 04-22-2005 at 09:06 AM.
Reply With Quote
  #4  
Old 04-22-2005, 08:39 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

While I'm not sure about the double-selection problem, I just thought I'd better point out a few things:

Code:
If List1.Text <> "" Or List1.Text <> "c:\media" Then Call Stopped

The above condition will never be False, no matter what List1.Text contains. If the text is "" then the second test is True, and if the text is "c:\media" then the first test is True. I think you should be using And rather than Or in that statement.

Code:
Do While WindowsMediaPlayer1.playState = wmppsStopped Loop

This is an incredibly tight loop. It will totally hold up your application, causing it to become unresponsive. I would suggest placing a DoEvents in there, and maybe a call to Sleep as well.

Well, as for the original problem, I would suggest placing a few breakpoints in your code and stepping through to see if you can spot what is causing AdvanceMedia to be called multiple times.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #5  
Old 04-22-2005, 10:10 AM
Deckstruction Deckstruction is offline
Newcomer
 
Join Date: Nov 2004
Location: Essex, UK
Posts: 14
Default

thanks, I used to be a PLC programmer so i worked extensively with Logical operations and in the type of coding i used to do that would have caused it to have carried out that instruction if either condition was valid. Thanks for the heads up on that

I've solved the problem of running that sub twice now:

Code:
Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long) If WindowsMediaPlayer1.playState = wmppsStopped And donealready = False Then Call AdvanceMedia If WindowsMediaPlayer1.playState = wmppsPlaying Then donealready = False If WindowsMediaPlayer1.playState = wmppsStopped And donealready = True Then WindowsMediaPlayer1.Controls.play End Sub Private Sub AdvanceMedia() If iclickedSTOP Then GoTo Skip If donealready = True Then GoTo Skip If List1.ListIndex < List1.ListCount - 1 Then List1.ListIndex = List1.ListIndex + 1 If List1.Text = "" Then GoTo Skip If List1.Text = "c:\media" Then GoTo Skip WindowsMediaPlayer1.URL = (List1.Text) Sleep (800) WindowsMediaPlayer1.Controls.play donealready = True Skip: End Sub
The problem was that (i think) windows media player enters the state "stopped" twice which was causing the sub to get called twice, I've also used that 'SLEEP' command you mentioned and it works fine.

Thanks for that mate
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->