Posts Tagged ‘mcml’

Code based dialogs in media center

Wednesday, March 10th, 2010

I’ve written a few posts on how to implement dialog boxes in media center (Adding a version checker and Simpler popup dialog). They are both great examples of how to trigger a dialog box in mcml. Suppose though you want to do it all from within code, not within mcml. Why would you want to do that? Well, for one it means not having any AddIn calls in your mcml, and AddIn calls mean you can’t use the mcml preview tool – which significantly hampers development. For this example, I’m going to repeat the Adding a version checker example, but all in code.

So, to trigger a dialog from your code, the first thing you need to do is to build some buttons;

ArrayListDataSet dialogButtons = new ArrayListDataSet();
dialogButtons.Add("Download Now");
dialogButtons.Add("Remind me later");
dialogButtons.Add("Ignore");

This adds 3 buttons to the dialog. Obviously add as many or as few as you like. The next thing you need to do is to add the call to open the dialog;

String dialogText="There is a new version available";
String dialogTitle="New Version";
Microsoft.MediaCenter.Hosting.AddInHost.Current
.MediaCenterEnvironment.Dialog(dialogText
, "dialogTitle, dialogButtons, 30, true, null
, new Microsoft.MediaCenter.DialogClosedCallback(versionCallback));

This will open a dialog as a modal dialog with a timeout of 30 seconds. When it is closed, the method?versionCallback will be called, so now we need to write that method;

public void versionCallback(Microsoft.MediaCenter.DialogResult result)
{
    if (result.ToString() == "100")
    {
        InstallNewVersion();
    }
    if (result.ToString() == "101")
    {
        RemindLater();
    }
    if (result.ToString() == "102")
    {
        IgnoreNewVersion();
    }
}

And obviously fill in the appropriate actions for each method.

Finally, you may want to block this dialog from triggering when you are in the debugger (since it won’t work), so put an if statement round it to stop it running in debug mode;

#if(!DEBUG)
   String dialogText="There is a new version available";
   String dialogTitle="New Version";
   Microsoft.MediaCenter.Hosting.AddInHost.Current
.MediaCenterEnvironment.Dialog(dialogText
  , "dialogTitle, dialogButtons, 30, true, null
  , new Microsoft.MediaCenter.DialogClosedCallback(versionCallback));
#endif

And that’s it – an mcml dialog operated entirely from your code.

Simpler popup dialog

Sunday, April 19th, 2009

In a previous post on adding a version checker to media center, I gave an example of how to write a popup dialog box for media center. There is also a simpler version of the Dialog if you don’t need to know anything about the response, e.g. if you are simply showing an information message. This simpler version doesn’t require a callback to be defined, or any complex button definitions. It just needs a title, some text, a button name, a timeout and whether or not it is modal. Here’s an example;

      <Condition Source="[Preferences.TwitDialog]" SourceValue="true" ConditionOp="ChangedTo">
        <Actions>
          <Set Target="[Preferences.TwitDialog]" Value="false"/>
          <Invoke Target="[AddInHost.MediaCenterEnvironment.Dialog]"
                  caption="Authorize Twitter"
                  text="Please authorize twitter."
                  buttons="Ok"
                  timeout="15"
                  isModal="true"/>

        </Actions>
      </Condition>

The buttons can only be ones from the list described in the documentation. A modal window requires either the user or a timeout to close it before any other actions can be done, whereas a modeless window allows the user to continue with other things in the meanwhile.

The dialog is fired in this example by a property which is set in the code to true, and then set back to false when it is read. The condition only fires when the value is set to true in the first place by using the ConditionOp.

Front End and Back End Synchronization in MCML

Sunday, April 19th, 2009

One of the issues that has been hardest for me to learn with developing media center applications as been the linking of front end items in the MCML layer with data that I have in c# on the back end. For a long time I struggled with binding values from the code in to front end, and making method calls from the front end in to the back end. I suspect that the reason I did this was because that is how it is shown in the Media Center SDK and documentation, so I thought it was the only way.

It turns out that the SDK is in fact showing the most complicated use case. There is a much easier way of linking the front end and the back end, that is so simple compared to the rest of MCML development that it’s almost non-intuitive. The technique is to create a UI item in your C# code, and then refer to that item on the front end. You don’t have two items, one front end and one back end. Instead you simply have one item that is referenced in both layers. That means that when you make a change to the value of the item in your C# code, the change is instantly reflected in the UI, and when you make a change to the value of the item in the UI, the C# code can reference that value instantly. Because it is the same physical item in memory. (more…)

Flash in windows media center

Friday, February 13th, 2009

Since my TunerFreeMCE code has been out there for almost a year now, I have picked up a fair bit of experience of playing flash on windows media center.

Most of the TV companies who provide flash video do so using the Akamai tech stack to secure and stream their content. They build their own custom flash players on top of that to provide their own flavour to the players, e.g. related videos and so on. The probably intentional side effect of this is that it is really not trivial to get in to their flash streams and do anything with it. It’s not like the have an rtmp url easily accessible for you to get hold of. There are ways of doing it, but not easily. There is for example a project on sourceforge called rtmpdump (http://sourceforge.net/projects/rtmpdump/) which allows you to download flash videos from the BBC and from Hulu. (more…)

Adding a version checker – code walkthrough

Monday, February 2nd, 2009

I was reading an article today on Symbian Guru about how more and more S60 developers are doing the right thing by including an automatic check for updates to their code. It guilted me in to realizing that it’s one of the big features that was missing from my TunerFreeMCE application. It also made me realize that I didn’t know what the best practice was for things like that, so I googled “c# check for new program version” and frankly what came back was irrelevant or overly complex. I had some very simple requirements;

  • Minimal web traffic – I pay for this hosting you know!
  • Minimal application impact
  • Easy for the user

(more…)