Thursday, May 10, 2007

Schedule recordings using ClickToRecord

I have written an application to schedule multiple recordings in MCE. To do this I used the ClickToRecord functionality descripted in the SDK. To use this functionality is simple - you just push a xml into the MCE API.

The code I have used to do this is:

private void doSchedule(string title, string date) {
  try {
    string xml =
    "<?xml version=\"1.0\" encoding=\"utf-8\" ?> " +
  "<clickToRecord xmlns=\"urn:schemas-microsoft-com:ehome:clicktorecord\">" +
    " <body>" +
    " <metadata><description>Scheduled with Mce Bulk Sceduler</description></metadata>" +
    " <programRecord prepadding=\"0\" postpadding=\"0\" isRecurring=\"false\">" +
    " <program>" +
    " <key field=\"urn:schemas-microsoft-com:ehome:epg:program#title\" match=\"exact\">" + title + "</key>" +
    " </program>" +
    " <airing timeZone=\"60\" searchSpan=\"10\">" +
    " <key field=\"urn:schemas-microsoft-com:ehome:epg:airing#starttime\">" + date + "</key>" +
    " </airing>" +
    " </programRecord>" +
    " </body>" +
    "</clickToRecord>";

    byte[] byteArr;
    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

    byteArr = encoding.GetBytes(xml);

    Microsoft.Windows.MediaCenter.ProgramDetails [] details;

    System.IO.Stream sr = new System.IO.MemoryStream(byteArr);

    ClickToRecord.Submit(sr,
        Microsoft.Windows.MediaCenter.ClickToRecord.ConflictResolutionPolicy.AllowConflict,
        out details);

  } catch (Exception ex) {
    WriteToLog(ex.ToString());
  }
}


The Api then searches the EPG data and schedules the recording if it finds a match. The Api is documented at MSDN: http://msdn.microsoft.com/library/en-us/MedctrSDK/htm/clicktorecordfeature.asp