Announcement

Collapse
No announcement yet.

MusicAPI and PlayChangeNotifyCallback

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MusicAPI and PlayChangeNotifyCallback

    I'm developing a plugin for HS2Pro that exposes the MusicApi to be used in HSTouch. So far, I have the basic structure of my plugin, have created two MusicApi interfaces and can use them both in HSTouch. I have been using the CurrentTrack and CurrentAlbumArtPath functions of the MusicApi and can draw them on my screens using the HomeSeer Music device.

    What I cannot get to work is the PlayChangeNotifyCallback which is essential to notify HSTouch to refresh the currently playing track!

    According to the scarcely detailed SDK, I need the following for PlayChangeNotifyCallback:

    * RaisesGenericCallbacks() to return True in my HSPI
    * The PlayChangeNotify event in HSMusicAPI class
    ? I need to RaiseGenericEventCB to notify of SongChanged
    ? I need to RegisterGenericEventCB
    ? I need to handle Generic Events in HSEvent

    I can't seem to make HSTouch do anything useful with the event in my plugin. I can see that HSTouch calls RaisesGenericCallbacks and then CurrentTrack and CurrentAlbumArtPath when it is first launched but never again after.

    There are barely any posts on here that talk about this. Can someone better describe the requirements to get HSTouch to talk with my plugin? Maybe explain how the event and event handler interact between HomeSeer, HSTouch, my HSPI and my HSMusicAPI class? Without PlayChangeNotifyCallback, my screens never update making it fairly useless.

    #2
    I suppose this has to do with me writing this plugin in C#.

    It is not possible to use RaiseEvent in C# so you need to write a delegate handler and then use the handler to raise the event. The issue I see is that if nothing registers to the handler it remains null and is impossible to raise.

    Code:
            public delegate void PlayChangeNotifyEventHandler(player_status_change ChangeType, ref object sender);
            public event PlayChangeNotifyEventHandler PlayChangeNotify;
    
            public void PlayChangeNotifyCallback(player_status_change ChangeType)
            {
                object me = null;
                if (PlayChangeNotify != null)
                    PlayChangeNotify(ChangeType, ref me);
                
            }
    Has anyone successfully used this case scenario in C# to raise PlayChangeNotify?

    Comment


      #3
      I found a workaround I'm happy with. I've created devices for my status strings and states so HSTouch updates whenever these change and I use hs.Plugin("HSTouch Server").ClientAction to force an update for my coverarts.

      This way I can avoid having to use the PlayChangeNotifyCallback.

      Comment


        #4
        Hello Burkilos,

        I have been fighting the same problem for a while now. I could not get any information until I read your post. I thought I did something wrong but now I understand that the PlayChangeNotifyCallback call is not working. Would you happen to have some more detailed information for me how you resolved this. I have created devices but these don't update in Hstouch either when I change them.

        Thanks
        Marcel

        Comment


          #5
          I'm sure the PlayChangeNotifyCallback works in VB using HS2Pro, in fact I've tested it. It's just that the way the functions are accessed from HomeSeer, the same does not seem to work when the plugin is coded in C#. This is my 6th plugin in C# for my HomeSeer setup and the first time that something does not work with the SDK.

          Since I'm not distributing this plugin, it was easy enough to hardcode it. I've created status devices in my plugin for the artist, title, playback status, etc... which update from my plugin. I added labels in HSTouch that track the status updates from these devices instead of using the MusicAPI features of HSTouch (this is basic stuff, nothing fancy).

          What was a bit more difficult to address, and the part that I had to hardcode, was the coverart of the media playing since I had to change the URL of the image within my HSTouch control. From my plugin, when the playback status changes or the media changes, I write a jpg with the coverart to the HomeSeer html folder and call the following within my plugin to change the ImageURLNormal path of the control (the control is named cover on the screen status Multimedia) in HomeSeer.

          Code:
          path = @"C:\Program Files (x86)\HomeSeer HSPRO\html\Cover_" + new Random().Next(1000, 9999) + ".png";
          hs.Plugin("HSTouch Server")).ClientAction(43, "", "status Multimedia:cover", path);
          Not exactly useful for someone that wants their plugin to work for others since it is specifically updating a control that probably only exists in my setup, but you could use variables and have ways for your customers or yourself to tell your plugin which screens / controls to update this way. Or, code it in VB

          I haven't looked at the current state of the MusicAPI in HS3 but since the last I saw it wasn't implemented yet, this may be a good workaround for you if that's what you are using.

          Comment


            #6
            Hello Burkilos,

            Thanks for the very useful feedback. I don't understand why the callback is not working but on the other hand I'm very green on this. This is my first plugin and it is not for commercial use. I am a JRMC fan and I just want a simple plugin that shows me what is playing and let me skip to the next song and change the volume. I bought the original source code and I'm trying to make it work with JRMC version 20. So far so good. I'm basically getting what i want only the screen update is not working.

            Following your advice I have created the devices and those are updating except the Album Art so i will try your method.

            FYI I'm using HS2.

            regards
            Marcel
            Last edited by MdeMan; July 15, 2015, 07:52 AM.

            Comment


              #7
              Hello Burkilos,

              Would you happen to have some VB sample code for using the hs.PlayChangeNotifyCallback.

              Thanks
              Marcel

              Comment

              Working...
              X