Freigeben über


Using FindService and PlayMedia to change the TV channel in Media Center

If you've used the MSN TV pages on Online Spotlight in Media Center you might have noticed buttons on some pages to tune to MSNBC or to The Weather Channel.  The page uses the Media Center API FindService to find which channel MSNBC is in your particular channel line up and then uses PlayMedia to change the channel (including starting TV if it is not currently in use).  Here's a script sample that shows how it works:

 function watchMSNBC()
{
    var rgServiceIDs = MCE.FindService("msnbc", ""); 
    if (rgServiceIDs.Length == 1) 
    { 
         MCE.PlayMedia(0, rgServiceIDs(0));
    }
    else 
    {
        // MSNBC isn't in the channel listing (or there are multiple channels called MSNBC)
    } 
}

First of all the code calls FindSerivce with the callsign of the channel, in this case "msnbc", the second parameter is used to find a term in the description of the channel - you'd use this if you wanted to tune to a channel that you didn't know the callsign of - for example you might want to tune to the local ABC channel without having to know the callsign for the channel in each local market.  FindService returns an array of channels that match the required attributes; in this case we're assuming that only one channel will be found.   Finally we start the channel playing using PlayMedia.  The first parameter is the type of media we want to start playing, in this case 0 for TV.  The second parameter is the ID of the channel that we want to tune to.  Instead of tuning to a particular channel using FindService it's possible to tune to a particular show if it is currently playing using FindProgram, but more on that another time.

This posting is provided "AS IS" with no warranties, and confers no rights.

Comments

  • Anonymous
    April 06, 2004
    Thank you, Michael, for this code!

    Can anyone tell me:

    Can I run the HTML page directly, or do I have to run it through an .MCL file?

    Is there anything the code is missing to run as is? Can anyone please provide that code?

    Where this code should be run?

    For example, can I call this function, "watchMSNBC()", onload of an HTML page, for example?

    Thanks a bunch!
    John
  • Anonymous
    April 06, 2004
    The comment has been removed
  • Anonymous
    April 07, 2004
    The comment has been removed
  • Anonymous
    April 09, 2004
    You'll need the guide to be download to use FindService and FindProgram.

    If you're having difficult downloading the guide, try disabling any popup blockers you have installed - some use a proxy that has caused problems for some people. I've also heard of some people having problems because their firewall was blocking the guide download.

    You can't programatically change channel up or down or tune to a numbered channel - this is because channel numbers of change between services and locations, so although the channel you want to tune to might be channel 13, it probably won't be that for everyone, hence changing by call sign or description is more reliable.
  • Anonymous
    April 10, 2004
    Thanks again for your replay =)

    Yet the Media Center allows the user to tune by local channel number and by up/down. I think it would be nice if the SDK allowed for this too.

    Efrat

  • Anonymous
    May 25, 2004
    Hi,

    I don't know if anybody can help but i can't seem
    to pick up a channel through the aerial port while playing through media center, it automatically searches for the received channels and manages to pick up 3/5 available. when i hook the aeriel up to a normal t.v all channels are found.. any suggestions..?

    Jamie
  • Anonymous
    May 25, 2004
    Hi,

    I don't know if anybody can help but i can't seem
    to pick up a channel through the aerial port while playing through media center, it automatically searches for the received channels and manages to pick up 3/5 available. when i hook the aeriel up to a normal t.v all channels are found.. any suggestions..?

    Jamie