Media won't play if called via invoke delegate

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
carled
New Cone
New Cone
Posts: 5
Joined: 13 Jul 2009 10:54

Media won't play if called via invoke delegate

Postby carled » 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:

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
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:

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
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...?

carled
New Cone
New Cone
Posts: 5
Joined: 13 Jul 2009 10:54

Re: Media won't play if called via invoke delegate

Postby carled » 14 Jul 2009 11:21

Update: it was me. I'd cracked the problem using the delegate. The new problem only became visible when I was looking at the log messages and it was saying, "can't open file". I realised that I was passing a carriage return in the filename too. Works a charm when that is stripped off!


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 43 guests