INTERACT FORUM

Please login or register.

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

Author Topic: Can somebody please help me with the COM object?  (Read 4347 times)

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Can somebody please help me with the COM object?
« on: March 19, 2015, 08:29:43 am »

I hope this is the correct forum, I'm guessing that those who could help me will be here! I have some old LUA code from the Girder website, made for Media Center 11. But obviously there has been a change somewhere along the way until the later versions, because it doesn't work. I'm pretty lousy at coding (well, to paraphrase Black Adder: I couldn't code myself out of a brown paper bag...  ;D ), so I can't really make heads or tails of this. Here's the code, which is meant to help me find out if a zone is playing or not:

Code: [Select]
local MC = false

local function GetJRMCObject()
    local o = luacom.GetObject ("MediaJukebox Application")
table.print (o)
    if o == nil then o = luacom.CreateObject ("MediaJukebox Application") end
    if o == nil then print ("Bummer!!") return false end
    return o
end

local function GetZonedPlayback(iZone)
assert(MC, 'No MC Object')
iZone = iZone or 0
local Zones = MC:GetZones()
--table.print(Zones)
local Zone = Zones:GetZone(iZone)
local Playback = Zone:GetPlayback()
assert(Playback, 'No Playback Object')
return Playback
end

local function Terminate ()
MC = nil
collectgarbage()
end

MC = GetJRMCObject()
local state = GetZonedPlayback(0)
print (state:State())
Terminate()

I can tell that it's managing to create the object, but it can't get the zones. Something tells me that it's MC:GetZones() that doesn't work since it doesn't seem to come up with a table (a table is created, but it's empty). But that can be totally wrong, of course. I tried to look at the automation stuff in the Wiki, but didn't really understand much, I'm afraid. As much as I like to call myself a power user I am far from a developer!  :-[ So could anybody please take pity in me?
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #1 on: March 21, 2015, 05:30:27 am »

No pity for the hopeless? ;)
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72442
  • Where did I put my teeth?
Re: Can somebody please help me with the COM object?
« Reply #2 on: March 21, 2015, 07:23:10 am »

I can't help, but the COM interface isn't much used now.  MCWS (on the DevZone) is.
Logged

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #3 on: March 21, 2015, 07:38:32 am »

Thanks, Jim! The web service, I see. Can I query that directly for playback state, or do I have to download a full XML format with all zones and states and info and then search in the XML to find the correct info?
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72442
  • Where did I put my teeth?
Re: Can somebody please help me with the COM object?
« Reply #4 on: March 21, 2015, 07:48:05 am »

I can't help with how to use it.  Sorry.  You can get a list of the commands by asking it.  It's self documenting. 
Logged

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #5 on: March 21, 2015, 07:51:20 am »

Yeah, I saw, thanks. I'll try that out.
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #6 on: March 21, 2015, 08:33:48 am »

And finally my head actually was good for something!  ;D I rarely manage to code, but this time I was actually able. Yeah, it's simple. Yeah, it's embarassing that I can't code better after all these years, but right now I'm very proud of myself!  ;) Note that I have 80 as the port, so I don't use port in this small pice of LUA code.

Code: [Select]
Playstate = string.sub(socket.http.request("http://192.168.0.15/MCWS/v1/Playback/Info?Zone=0"), 166,166)
print (Playstate)

Edit: I had to mess up a bit, or it wouldn't have been me.  :-[ This of course doesn't take into account the different zone names. To avoid the length of zone names messing up, I can do it like this:

Code: [Select]
local i = string.find(socket.http.request("http://192.168.0.15/MCWS/v1/Playback/Info?Zone=0"), 'State">')
print (i)
Playstate = string.sub(Page, i+7, i+7)
print (Playstate)
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Can somebody please help me with the COM object?
« Reply #7 on: March 21, 2015, 09:01:50 am »

And finally my head actually was good for something!  ;D I rarely manage to code, but this time I was actually able. Yeah, it's simple. Yeah, it's embarassing that I can't code better after all these years, but right now I'm very proud of myself!  ;) Note that I have 80 as the port, so I don't use port in this small pice of LUA code.

Code: [Select]
Playstate = string.sub(socket.http.request("http://192.168.0.15/MCWS/v1/Playback/Info?Zone=0"), 166,166)
print (Playstate)

Just a little note that you probably don't want to assume the playstate is 166 characters in.  It'd be much better to search the string for the play state marker and read there.
Logged
Matt Ashland, JRiver Media Center

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #8 on: March 21, 2015, 09:03:35 am »

Wow, synchronized posting, Matt! Just like synchronized swimming, except for the lack of bathing suits. Well, I don't wear one. I don't know about you! ;)

To be more precise you posted while I was editing my post. Anyway thanks a lot, that ide was very correct!
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #9 on: March 21, 2015, 09:51:19 am »

I hit a snag. A big one. I thought there was something wrong with my code, because I didn't get any info except for "<Response Status="OK"/>". Turned out that there wasn't. But I think that either I misread the documentation, or there is something wrong, because for any zone but 0 this will only give you "<Response Status="OK"/>" as the answer:

Code: [Select]
http://192.168.0.15/MCWS/v1/Playback/Info?Zone=1
What do I need to put in to get it to work on other zones? I tried the part with the ZoneType, but this code doesn't work either:

Code: [Select]
http://192.168.0.15/MCWS/v1/Playback/Info?Zone=1&ZoneType=ID
In Girder I see this response:
Quote
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Response Status="OK"/>
Which is basically the same.

I feel I'm about one step away from the solution, but it keeps moving away each time I take another step! ;)
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Can somebody please help me with the COM object?
« Reply #10 on: March 21, 2015, 10:22:12 am »

You need to call http://localhost:52199/MCWS/v1/Playback/Zones to get the list of zones.

Then plug each ID returned into the call:
http://localhost:52199/MCWS/v1/Playback/Info?Zone=[enter zone number here]
Logged
Matt Ashland, JRiver Media Center

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #11 on: March 21, 2015, 10:38:47 am »

Thanks, Matt! I see that I get output from 0, then 10000 and up to 10007, and then 10021-10023. Do these change at any time (except for the very rare occasions where I add or delete zones), or are they set in stone? If they are I can do a translate table for that. Or is there a logic in this that I can use?
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system

Mastiff

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1988
  • The Multi-Zone Tzar
Re: Can somebody please help me with the COM object?
« Reply #12 on: March 22, 2015, 05:06:32 am »

Never mind, I managed to get together (with a little help...) code that first checked the zone ID, no matter how many digits, and then sendt the check to that zone. :)
Logged
Tor with the Cinema Inferno & Multi-Zone Audio system
Pages: [1]   Go Up