I am writing an audio program in VB.net 2005 and I am having a bit of trouble with WMP.
I can get media added to the playlist and I can play it from there, but it doesn't load until I press play, which gives a slight delay while the media loads.
It also means that I cannot retrieve the length of the media untl it has been played.
Can anyone guide me on how to get the media loaded and ready, without having to play it.

This is the code I am currently using to add to the playlist:

Dim song = mPlayer.newMedia(Playlist.FileList.Items(0))
                mPlayer.currentPlaylist.appendItem(song)

And then:

mPlayer.Ctlcontrols.play()

to play it

If anyone can help I would be very grateful. I'm sure it's a simple answer but I just can't find it lol.

Well I haven't found the answer but I have found a work around.

By setting the Autoplay property to true and monitoring the OpenStateChange for the file to be open and instantly stopping it, the media is loaded without starting to play.

Member Avatar for Dukane

There really isn't a way to do this using WMP because you are restricted to the way WMP handles files. To get a true instant start you would need to first load the file into the computer's memory and then somehow instruct Windows Media Player to play that file from the memory, without first loading it.

I don't know how to do this.

Can somebody please tell me how do i create a playlist for my media player in VB.Net. My media player is able to select one file n play it. But how do i create the playlist.. or may be a library.. one more feature i want to add is format conversion. coz media player is able to play only mp3 and avi. i want other formats like VOB also..

hye ...i have solution to your problem.......I have done my labtask in which a media file of AVI,WMV,MOV,MP4 can easily be played.........
i'm going to write the code below.....
this code has been written by me in Visual Studio 2008.........
if any query or any problem,u want to solve...contact me on
owaiskhan772@yahoo.com
The code is as follows..

Public Class Form1
Dim o As New OpenFileDialog
Private Sub OpenFileToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileToolStripMenuItem.Click

Try
o.RestoreDirectory = True
o.Filter = "AVI Videos (*.avi)|*.avi|WMV Videos (*.wmv)|*.wmv|MOV Videos (*.mov)|*.mov|MP4 Videos (*.mp4)|*.mp4"
o.FilterIndex = 1
o.FileName = ""
o.ShowDialog()

If o.ShowDialog() = Windows.Forms.DialogResult.OK Then
AxWindowsMediaPlayer1.URL = o.FileName()
End If

Catch ex As Exception
MessageBox.Show("Some error occur so can't play media", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub


Private Sub Form1_ClientSizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ClientSizeChanged
AxWindowsMediaPlayer1.Size() = Me.ClientRectangle.Size()
End Sub

Private Sub MinimalViewToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.AxWindowsMediaPlayer1.uiMode() = "none"
End Sub

Private Sub FullModeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.AxWindowsMediaPlayer1.uiMode = "full"
End Sub


Private Sub ExitToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub

Private Sub PlayToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub

Private Sub StopToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub

Private Sub PauseToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PauseToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub

Private Sub UpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpToolStripMenuItem.Click
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
End Sub

Private Sub DownToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownToolStripMenuItem.Click
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume - 10
End Sub

Private Sub MuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MuteToolStripMenuItem.Click

If AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.mute() Then

AxWindowsMediaPlayer1.settings.volume = 20

Else
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.mute()
End If

End Sub
End Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.