Media won't play if called via invoke delegate
Posted: 13 Jul 2009 11:06
Hi all. Just started doing a vb.net prog.
Very simple concept, the player sits there listening for events on the serial port, once received, it starts playing that media.
If I put a drop down box on the page and select the media file, it successfully plays the media like this:
Now as the windows form is on a different thread to the event listener, if I try and access the vlc control via that thread, I get a "cross-thread exception" and rightly so. I therefore used a delegate:
Now in debug, I can see I no longer get the cross-thread exception, yahoo! However, directly after the "vlc.playlist.playItem(item)" in the playMedia sub, I check on "playlist.isPlaying" and it changes immediately to "false"...
Any ideas where I'm going wrong please? Seems simple, should work...?
Very simple concept, the player sits there listening for events on the serial port, once received, it starts playing that media.
If I put a drop down box on the page and select the media file, it successfully plays the media like this:
Code: Select all
(in "play" button pressed sub)
playMedia(combobox1.selectedItem)
Private Sub playMedia()
Dim vlc As AxAXVLC.AxVLCPlugin2 = AxVLCPlugin21
If (vlc.playlist.items.count > 0) Then
If (vlc.playlist.isPlaying) Then
vlc.playlist.stop()
End If
vlc.playlist.items.clear()
End If
Dim item As Integer = vlc.playlist.add("c:\media\" + mediaString) 'mediastring is global variable
vlc.playlist.playItem(item)
mediaString = ""
End Sub
Code: Select all
Public Delegate Sub myVLCDelegate()
(and in my "event received" subroutine:)
Private Sub DataReceived( _
ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles serialPort.DataReceived
Dim x As String = serialPort.ReadExisting
mediaString += x
If x = Chr(13) Then
'playMedia(mediaString) '(can't do this - cross thread exception)
If InvokeRequired Then '(this always comes up with "true")
Invoke(New myVLCDelegate(AddressOf playMedia), New Object() {})
End If
End If
End Sub
Any ideas where I'm going wrong please? Seems simple, should work...?