INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: MC Events  (Read 2601 times)

llafriel

  • World Citizen
  • ***
  • Posts: 230
MC Events
« on: June 15, 2010, 12:42:23 am »

Hello,

I'm trying to get events working with vb.net. I've followed the wiki, and also some of the older posts here but it doesn't work. Anyone got any clues? I want to now whether a zone is playing, paused or stopped. 


Code: [Select]
Public Class MainInterface
#Region "Private Attributes"
    'This is the Interface to Media Center
    'This is set when Media Center calls the Init Method 
    Private mediaCenterRef As MediaJukebox.MJAutomation
#End Region

#Region "Media Center Initialisation"
    ' <summary>
    ' After the plugin has been created Media Center
    ' will call the following method, giving us a reference
    ' to the Media Center interface.
    ' </summary>
    ' <param name="mediaCenterReference">
    ' Media Center Reference
    ' </param>       
    Public Sub init(ByVal mediaCenterRef As MediaJukebox.MJAutomation)
        Try
            Me.mediaCenterRef = mediaCenterRef
        Catch ex As Exception
            MessageBox.Show("")

        End Try
    End Sub
#End Region
    Dim WithEvents MC As MediaCenter.MCAutomation
    Private _RelayEvent As RelayEvent
    Delegate Sub RelayEvent(ByVal EventData1 As String, ByVal EventData2 As String, ByVal EventData3 As String)

    Public Declare Function tdTurnOn Lib "TelldusCore.dll" (ByVal lngDeviceId As Integer) As Boolean
    Public Declare Function tdTurnOff Lib "TelldusCore.dll" (ByVal lngDeviceId As Integer) As Boolean
    Public Declare Function tdBell Lib "TelldusCore.dll" (ByVal lngDeviceId As Integer) As Boolean
    Public Declare Function tdDim Lib "TelldusCore.dll" (ByVal lngDeviceId As Integer, ByVal level As Byte) As Boolean
    Public Declare Function tdMethods Lib "TelldusCore.dll" (ByVal lngDeviceId As Integer, ByVal methodsSupported As Short) As Integer
    Public Declare Function tdGetDeviceId Lib "TelldusCore.dll" (ByVal a As Integer) As Integer
    Public Declare Function tdGetName Lib "TelldusCore.dll" (ByVal i As Integer) As String
    Public Declare Function tdGetNumberOfDevices Lib "TelldusCore.dll" () As Integer

    Private Sub MyRelayEvent(ByVal EventData1 As String, ByVal EventData2 As String, ByVal EventData3 As String)
        'lbParam1.Text = EventData1
        'lbParam2.Text = Trim(EventData2)
        ' lbParam3.Text = EventData3
        ' Application.DoEvents()
        MsgBox("ahoy")
    End Sub

    Public Sub MC_FireMJEvent(ByVal s0 As String, ByVal s1 As String, ByVal s2 As String) Handles MC.FireMJEvent
        _RelayEvent = New RelayEvent(AddressOf MyRelayEvent)
        BeginInvoke(_RelayEvent, s0, s1, s2)
        MsgBox("ahoy")
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim devices As String = tdGetNumberOfDevices
        Dim deviceid(devices - 1) As String
        For i As Integer = 0 To devices - 1
            deviceid(i) = tdGetDeviceId(i)
        Next
        tdTurnOn(deviceid(0))
    End Sub
End Class
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4565
Re: MC Events
« Reply #1 on: June 15, 2010, 02:33:06 am »

im not sure i do it as it should, but this is what i use and what works. i also started with the plugin from mr. chriz a long time agon, so im not sure what i changed. but this is in essence how it looks (i took all únnessesary things away now):
Code: [Select]
Public Class MainInterface
#Region "Private Attributes"
    'This is the Interface to Media Center
    'This is set when Media Center calls the Init Method 
    Private WithEvents mediaCenterRef As MediaCenter.MCAutomation
#End Region

#Region "Media Center Initialisation"
    ' <summary>
    ' After the plugin has been created Media Center
    ' will call the following method, giving us a reference
    ' to the Media Center interface.
    ' </summary>
    ' <param name="mediaCenterReference">
    ' Media Center Reference
    ' </param>       
    Public Sub init(ByVal mediaCenterRef As MediaCenter.MCAutomation)
        Try
            Me.mediaCenterRef = mediaCenterRef
        Catch ex As Exception
            MessageBox.Show("")
        End Try
    End Sub

#End Region

    Private Sub MJEvent(ByVal s1 As String, ByVal s2 As String, ByVal s3 As String) Handles mediaCenterRef.FireMJEvent
        Dim zoekA As String
        If s2 = "MCC: NOTIFY_TRACK_CHANGE" Then
            'blahblah()
            MsgBox(s1 & s2 & s3)
        End If

    End Sub


 :)
gab
Logged

llafriel

  • World Citizen
  • ***
  • Posts: 230
Re: MC Events
« Reply #2 on: June 15, 2010, 03:49:44 am »

Thanks gab. Got it working now :)
Is there any way of seeing events from inactive zones?
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4565
Re: MC Events
« Reply #3 on: June 15, 2010, 04:11:26 am »

 8) good.
some events are sent also for the inactive zones, for others it is not interesting (like when playlists change), i just tested the MCC: NOTIFY_TRACK_CHANGE i use and it got fired on a trackchange in zone 0 although zone 2 was active. you can see that when using the msg box, the s3 gives the zone number where the change took place.
the same should be true for MCC: NOTIFY_PLAYERSTATE_CHANGE

 :)
gab
Logged

llafriel

  • World Citizen
  • ***
  • Posts: 230
Re: MC Events
« Reply #4 on: June 15, 2010, 07:00:17 am »

Is it just me or is the forum slow today?
How do I know what state the player is in? Paused, stopped or playing? Also, one skip seems to generate 4-5 events.
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71347
  • Where did I put my teeth?
Re: MC Events
« Reply #5 on: June 15, 2010, 08:14:52 am »

It is slow.  We're working on it.  Sorry.
Logged

llafriel

  • World Citizen
  • ***
  • Posts: 230
Re: MC Events
« Reply #6 on: June 15, 2010, 12:29:52 pm »

Never mind, found it in an older post.

Code: [Select]
        Dim PlayBackObj As Object
        PlayBackObj = mc.GetPlayBack()
        Dim PlayBackStatus As Integer = -1 ' Set to -1 one so that I can easily see if level has been set !
        PlayBackStatus = PlayBackObj.State() '0-Stopped 1-Paused 2-Playing 3-Waiting

Which also answered why there were so many events fired.
Logged
Pages: [1]   Go Up