By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,696 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,696 IT Pros & Developers. It's quick & easy.

How to do Multi-Threading

P: n/a
Hi,
I need to use Windows Meadia Player control in my application to run som
mpeg movies. There is no user interface, I need to control everything
programatically. I do not want to use the playlist facility of the Windows
Media Player Control, I want to queue up the files to play myself. In order
to do that I need to know when the current file has been played and the
player has stopped.
I am looking at multi-threading as a solution, but am having difficultly
with the algorithm. I get the main thread to start the first clip and get
the worker function to check when the player has stopped the first clip, but
then I am wondering where I put the code to load the next mpeg file and
start the worker function again. Below is some snipits of code. Any help
would be appreciated.
Michael Murphy
md******@scs-techresources.com
954-452-1047

Imports System.Threading

Public Class frmMain

Inherits System.Windows.Forms.Form

Dim startworker As ThreadStart

Dim workerThread As Thread

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

startworker = New ThreadStart(AddressOf workerfunction)

workerThread = New Thread(startworker)

'DoCreate()

workerThread.Start()

End Sub

Public Sub DoCreate()

AxWindowsMediaPlayer1.uiMode = "none" ' no user interface, just the
player

If AxWindowsMediaPlayer1.URL = "" Then

AxWindowsMediaPlayer1.URL = GetNextAdvertisementFileName("Started")
' first time through

Else

AxWindowsMediaPlayer1.URL =
GetNextAdvertisementFileName(AxWindowsMediaPlayer1 .URL) ' pass function the
last one played

End If

If workerThread.ThreadState = ThreadState.Stopped Then

workerThread.Start()

End If

End Sub

Private Sub workerfunction()

While (1)

If AxWindowsMediaPlayer1.playState <> WMPLib.WMPPlayState.wmppsStopped And
AxWindowsMediaPlayer1.playState <> WMPLib.WMPPlayState.wmppsUndefined Then

Thread.Sleep(700)

Else

Exit While

End If

End While

DoCreate()

End Sub

Private Function GetNextAdvertisementFileName(ByVal LastFileName As String)
As String

'stub out with these two mpeg files alternating for now

If LastFileName = "C:\Documents and Settings\MDMurphy\My Documents\Visual
Studio Projects\GasStationAdvert\ranier.mpg" Then

GetNextAdvertisementFileName = "C:\Documents and Settings\MDMurphy\My
Documents\Visual Studio Projects\GasStationAdvert\experience.mpg"

Else

GetNextAdvertisementFileName = "C:\Documents and Settings\MDMurphy\My
Documents\Visual Studio Projects\GasStationAdvert\ranier.mpg"

End If

End Function

End Class

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Michael,

I think you may try to use the code to see if that is what you want.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.AxWindowsMediaPlayer1.URL = "c:\a.wma"
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
'handle the PlayStateChange event to be notified when the song has been
stopped
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As
Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles
AxWindowsMediaPlayer1.PlayStateChange
If e.newState = Me.AxWindowsMediaPlayer1.playState.wmppsStopped
Then
BeginInvoke(New MethodInvoker(AddressOf PlayIm))
End If
End Sub
Private Sub PlayIm()
Me.AxWindowsMediaPlayer1.URL = "c:\b.wma"
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(Me.AxWindowsMediaPlayer1.URL)
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

P: n/a
Peter,

I had the plan to do this, so thanks that you did it, I am as well curious
if this fit the problem.

Cor

""Peter Huang"" <v-******@online.microsoft.com>
Hi Michael,

I think you may try to use the code to see if that is what you want.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.AxWindowsMediaPlayer1.URL = "c:\a.wma"
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
'handle the PlayStateChange event to be notified when the song has been
stopped
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As
Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles
AxWindowsMediaPlayer1.PlayStateChange
If e.newState = Me.AxWindowsMediaPlayer1.playState.wmppsStopped
Then
BeginInvoke(New MethodInvoker(AddressOf PlayIm))
End If
End Sub
Private Sub PlayIm()
Me.AxWindowsMediaPlayer1.URL = "c:\b.wma"
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(Me.AxWindowsMediaPlayer1.URL)
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Nov 21 '05 #3

P: n/a
Peter,
Thanks for the help. I cut and pasted what I needed and with a few tweaks
here and there, it works great!
And Cor, thank you, too for following along on this.
We sure have a nice communitiy here, now don't we??
Michael

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:tu*************@cpmsftngxa06.phx.gbl...
Hi Michael,

I think you may try to use the code to see if that is what you want.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.AxWindowsMediaPlayer1.URL = "c:\a.wma"
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
'handle the PlayStateChange event to be notified when the song has been
stopped
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As
Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles
AxWindowsMediaPlayer1.PlayStateChange
If e.newState = Me.AxWindowsMediaPlayer1.playState.wmppsStopped
Then
BeginInvoke(New MethodInvoker(AddressOf PlayIm))
End If
End Sub
Private Sub PlayIm()
Me.AxWindowsMediaPlayer1.URL = "c:\b.wma"
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(Me.AxWindowsMediaPlayer1.URL)
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #4

P: n/a
Hi Michael,

I am glad the suggestion help you.
Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.