 |
 |

04-21-2005, 01:41 PM
|
|
Newcomer
|
|
Join Date: Nov 2004
Location: Essex, UK
Posts: 14
|
|
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
|
|

04-21-2005, 01:50 PM
|
|
Senior Contributor
* Expert *
|
|
Join Date: May 2004
Location: Manchester, England.
Posts: 1,254
|
|
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.
|
|

04-22-2005, 08:32 AM
|
|
Newcomer
|
|
Join Date: Nov 2004
Location: Essex, UK
Posts: 14
|
|
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.
|

04-22-2005, 08:39 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
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.
|
|

04-22-2005, 10:10 AM
|
|
Newcomer
|
|
Join Date: Nov 2004
Location: Essex, UK
Posts: 14
|
|
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 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|