vb media player - next song automatically
Hi,
I am a quite experiences programmer and started coding a vb media player yesterday. Its basically done apart from i cant get the player to automatically load the next song. I have done a search of this forum but none of the previous responses seem to work.
Heres the code :
Private Sub WMP_StatusChange()
If WMP.playState = wmppsMediaEnded Then
If OptOn.Value = True Then
filecount = File1.ListCount
chosenfile = Int(Rnd * filecount) + 1 'generate random index
File1.Selected(chosenfile) = True
filename = Dir1.Path & "\" & File1.filename
WMP.URL = filename
Else
fileindex = File1.ListIndex
fileindex = fileindex + 1
File1.Selected(fileindex) = True 'plays next index
filename = Dir1.Path & "\" & File1.filename
WMP.URL = filename
End If
End If
End Sub
I have tried different events as well like playstatechange but no luck. The very annoying thing is that an identical piece of code works on a button click.
Any response would be appreciated
Thanks in advance
Juggler
Re: vb media player - next song automatically
How about using a Play List?
Re: vb media player - next song automatically
if you mean a pre-determined list of songs to run through that is not what i am after. Can you see any prob with the code and any suggestion why it will work onclick but not on any media event i have tried so far.
Juggler
Re: vb media player - next song automatically
Ok I think what you should be doing is generating a temporary playlist that you can generate from your files in the selected directory. Then assign the new temp playlist as the active list and play it.
.newPlaylist "MyTempPlaylist1", "C:\SomeFolder\TempList1.wpl"
.settings.setMode wmppsPlaying, True
This is how most sites do it with those continuous playing of videos.
Re: vb media player - next song automatically
ok thanks. I will have a play and let you know the outcome.
cheers - juggler
Re: vb media player - next song automatically
Re: vb media player - next song automatically
had a play but no luck. So it is possible to put all the mp3 files in one directory into a playlist on form load. If so could you maybe post some code to get me started, if you know it that is.
Thanks
Juggler
Re: vb media player - next song automatically
Write out your playlist file in this format after you read in the files in your directory.
Playlist format:
Code:
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 11.0.6000.6344"/>
<meta name="AverageRating" content="33"/>
<meta name="TotalDuration" content="111"/>
<meta name="ItemCount" content="3"/>
<meta name="ContentPartnerListID"/>
<meta name="ContentPartnerNameType"/>
<meta name="ContentPartnerName"/>
<meta name="Subtitle"/>
<author/>
<title>Test</title>
</head>
<body>
<seq>
<media src="Video1.wmv"/>
<media src="Video2.wmv"/>
<media src="Video3.wmv" />
</seq>
</body>
</smil>
The to load/play it:
Code:
Option Explicit
Private Sub Form_Load()
WMP.URL = "C:\Users\UserName\Videos\Test.wpl"
End Sub
Re: vb media player - next song automatically
Seems you need to invoke the play too.
Code:
Option Explicit
Private Sub Form_Load()
On Error GoTo My_Error
WMP.URL = "C:\Users\UserName\Videos\Test.wpl"
WMP.Controls.play
Exit Sub
My_Error:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
End Sub
Media Player Play Next Song Automatically
How to create media player with play next song automatically
Timer1.Tick
Timer1.Start()
If Me.AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
ListBox1.SelectedIndex = (Index Mod ListBox1.Items.Count)
Index += 1
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
This is the code
Codes By Sricharan
1 Attachment(s)
Re: vb media player - next song automatically
This sample media player uses msdxm.ocx (included unless moderator removed it). It uses a Play list
Re: vb media player - next song automatically
@Sricharan: Welcome to the forums. I have deleted the attachment from your post as it contained an executable file. When ever you upload attachments in vbforums, please ensure that it doesn't have an executable file in it. Also this thread is for Visual Basic 6 so your code actually is of no use :)