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