INTERACT FORUM

Please login or register.

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

Author Topic: Issue with MC Automation (out-of-proc)  (Read 6121 times)

JeffreyK

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 52
  • nothing more to say...
Issue with MC Automation (out-of-proc)
« on: September 21, 2003, 07:18:21 am »

I'm trying to use the new out of proc automation of MC in a program I am writing, but am running into a small problem.

If MediaCenter is NOT running, my program runs fine (MediaCenter launches and then exits when my program exits) and I can run it a second time with no problems.  

If MediaCenter IS running, my program works fine the first time, but when run a second time, MC is made the active app and, after a few seconds, my program errors out due to the CreateInstance call failing.

Any thoughts?  The code I am using is below.  Build is 252 and I'm on WinXP.

Thanks!
-Jeff

Code: [Select]
CoInitialize(NULL);
IMJAutomationPtr mj;
HRESULT hr = mj.GetActiveObject(L"MediaJukebox Application");
if (hr == S_OK)
   mj.AddRef();
else
   mj.CreateInstance("MediaJukebox Application");

if (mj == NULL)
{
   printf("Failed to create MediaJukebox object!\n");
   return 1;
}

IMJCurPlaylistAutomationPtr pMJCurPlaylist = mj->GetCurPlaylist();

if (pMJCurPlaylist == NULL)
{
   printf("Failed to get CurPlaylistAutomation object!\n");
   return 1;
}

if (pMJCurPlaylist->GetNumberFiles() == 0)
{
   printf("No files in Now Playing.\n");
   return 1;
}

int iFile = pMJCurPlaylist->GetPosition();
IMJFileAutomationPtr pMJCurFile = pMJCurPlaylist->GetFile(iFile);

if (pMJCurFile == NULL)
{
   printf("Failed to get the current file object!\n");
   return 1;
}
Logged

JeffreyK

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 52
  • nothing more to say...
Re: Issue with MC Automation (out-of-proc)
« Reply #1 on: September 21, 2003, 07:27:48 am »

Hmm - I was doing more debugging on this and it stopped happening.  Now everything works fine (with no code changes in my program).

I'll keep playing with it and if I can get it to happen again, I'll try to figure out more information about what might be causing it.

-Jeff
Logged

JeffreyK

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 52
  • nothing more to say...
Re: Issue with MC Automation (out-of-proc)
« Reply #2 on: September 21, 2003, 07:42:51 am »

Ok - one issue that I'd like someone on the MC dev team to look into is the AddRef after a successful GetActiveObject.  I seem to remember (and some quick browsing of MSDN doesn't show me anything to discount this) that GetActiveObject already returns a refcounted object.

That AddRef, however, I don't think is the cause of my problem (which has returned).

A little more debugging shows that when the problem happens, the call to GetActiveObject (which should succeed since MC is already running) returns:
   hr = 0x800401e3 "Operation unavailable"
Then the CreateInstance call works.  The second run of the program, the GetActiveObject fails again in the same way, but this time the CreateInstance call also fails.

This happens even if MC was just launched.  (I am not sure what caused the GetActiveObject to start working on my machine for a bit, but when I tried to exit MC after it was working, MC just hung, so something was in a weird state.)

Any thoughts?
Thanks!
-Jeff
Logged

JeffreyK

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 52
  • nothing more to say...
Re: Issue with MC Automation (out-of-proc)
« Reply #3 on: September 22, 2003, 01:41:34 pm »

No one has any thoughts on this?

I've tried it on a second computer (running .256) with the same problems.

Here is a small test file that I've built so that others can try it (it is basically the sample code from the devzone page with printf statements in it to help debug):
http://home.comcast.net/~jeffrey.krauss/test/test.cpp
http://home.comcast.net/~jeffrey.krauss/test/test.exe

If you run it when MC is not running, it should result in:
GetActiveObject failed, hr = 800401e3
CreateInstance succeeded

If you then launch MC and run the program twice, you should get:
GetActiveObject failed, hr = 800401e3
CreateInstance succeeded

GetActiveObject failed, hr = 800401e3
CreateInstance failed

Can other folks at least try this out to see if you get the same result?

Thanks!
-JeffreyK
Logged

Nikolay

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 1681
  • Former CTO, JRiver, Inc.
Re: Issue with MC Automation (out-of-proc)
« Reply #4 on: September 23, 2003, 12:55:15 pm »

JeffreyK,

Sorry about confusion, but AddRef call is not neccessary with new builds of Media Center.

Take a look a new version of MJAutomation documentation to see the new way.

Nikolay
Logged

Nikolay

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 1681
  • Former CTO, JRiver, Inc.
Re: Issue with MC Automation (out-of-proc)
« Reply #5 on: September 23, 2003, 01:36:58 pm »

Ignore my previous message. We found a bug in our code which prevents the automation to be initialized second time.

The fixed will be available in the next build.

Thanks,
Nikolay
Logged

JeffreyK

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 52
  • nothing more to say...
Re: Issue with MC Automation (out-of-proc)
« Reply #6 on: September 23, 2003, 01:40:32 pm »

Thanks!

-JeffreyK
Logged

mjcumming

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 53
  • nothing more to say...
Re: Issue with MC Automation (out-of-proc)
« Reply #7 on: October 01, 2003, 08:47:23 am »

Where is the documentation for using the out of process automation/object?
Logged

Soundman

  • Regular Member
  • World Citizen
  • ***
  • Posts: 155
  • Go Music!
Re: Issue with MC Automation (out-of-proc)
« Reply #8 on: October 01, 2003, 08:19:32 pm »

mjcumming,


The code sample in JeffreyK's post that started this thread shows how to instantiate an Automation object out of process.

Once you have that, the methods, objects, & properties that you can use are documented here:

http://www.musicex.com/mediacenter/devzone.html

Follow the first link, "Media Center automation"

-- Soundman
Logged

mjcumming

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 53
  • nothing more to say...
Re: Issue with MC Automation (out-of-proc)
« Reply #9 on: October 02, 2003, 05:42:20 am »

Okay thanks, so there is no real advantage over using MCIO.  I thought maybe the API had been updated or improved.
Logged

Soundman

  • Regular Member
  • World Citizen
  • ***
  • Posts: 155
  • Go Music!
Re: Issue with MC Automation (out-of-proc)
« Reply #10 on: October 02, 2003, 08:28:06 am »

mjcumming,

No, there is no advantage over MCIO as of now.  In fact, in this thread:
http://www.musicex.com/cgi-bin/yabb/YaBB.cgi?board=dev;action=display;num=1061819687

I pointed out that MCIO is actually faster (by a facter of 2X) than using Media Center Automation directly.  This is very counterintuitive, and Nikolay said that he will look into the performance issue.

As for the API, I have been begging for the API to be improved for some time now, as have some others.  I think JRiver will get to it eventually.  In the meantime, my HTPC project is kinda stuck.

Good Luck,
Soundman
Logged
Pages: [1]   Go Up