Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

7MC Gofer

0.00/5 (No votes)
23 Jun 2010 1  
7MC Gofer is a Windows Phone 7 based remote control for my Windows Media Center.

A gofer or go-fer (pronounced /'go?f?r/ "Topo") is an employee who is often sent on errands.

Introducing 7MC Gofer

7MC Gofer is a Windows Phone 7 based remote control for my Windows Media Center.

Installing Vista Media Center TCP/IP Controller

Download the Windows 7 version here.

Before we can start, we need a way of controlling our 7MC. Vista Media Center TCP/IP Controller is a small addin for 7MC which hosts an HTTP-like server that accepts simple commands (like button-up, volume, etc.).

Once installed, test the service by navigating to the following URL using your browser (http://localhost:40510/help).

I also created an EXTREMELY simple wrapper for executing commands:

C#
public</span /> class</span /> MceService
{
    const</span /> string</span /> endPointServer = "</span />localhost"</span />;

    private</span /> void</span /> ExecuteCommand(string</span /> command, params</span /> object</span />[] args)
    {
        string</span /> requestUriString = string</span />.Format
		("</span />http://{0}:40510/{1}"</span />, endPointServer, command);
        foreach</span /> (var</span /> arg in</span /> args)
        {
            requestUriString += "</span />%20"</span />;
            requestUriString += arg;
        }

        Console.WriteLine(requestUriString);

        var</span /> request = (HttpWebRequest)WebRequest.Create(requestUriString);
        request.Method = "</span />GET"</span />;
        request.BeginGetResponse(ExecuteCommandCallback, null</span />);
    }

    static</span /> void</span /> ExecuteCommandCallback(IAsyncResult result) { }

    public</span /> void</span /> Goto(string</span /> parameter)
    {
        ExecuteCommand("</span />goto"</span />, parameter);
    }

    //</span /> The reset is removed for brevity
</span />}

This is based on the code demoed by Dan & Clint @ Tech-ed (you have to watch their video).

MVVM Light Toolkit

Download the toolkit here (also read the Get Started).

The last thing we need to cover before we can start is the MVVM Light Toolkit. It’s a GREAT MVVM toolkit created by Laurent Bugnion. I am using this framework for 2 main reasons, locating the ViewModel...

C#
DataContext="</span />{Binding Main, Source={StaticResource Locator}}"</span />

...and hooking up the commands… Here is the command (In my ViewModel):

C#
private</span /> RelayCommand backCommand;
public</span /> RelayCommand BackCommand
{
    get</span />
    {
        if</span /> (backCommand == null</span />)
            backCommand = new</span /> RelayCommand(() => 
                {
                    //</span /> Do your work here...
</span />                });

        return</span /> backCommand;
    }
}

And in the View?

XML
<</span />Button</span /> Content</span />="</span />Back"</span />></span />
    <</span />i:Interaction.Triggers</span />></span />
        <</span />i:EventTrigger</span /> EventName</span />="</span />Click"</span />></span />
            <</span />cmd:EventToCommand</span /> Command</span />="</span />{Binding BackCommand}"</span /> /</span />></span />
        <</span />/</span />i:EventTrigger</span />></span />
    <</span />/</span />i:Interaction.Triggers</span />></span />
<</span />/</span />Button</span />></span />

MVVM Light Toolkit makes this extremely easy!

Creating a Windows Phone 7 Client

Windows Phone

Download the tools here.

Now that we have the basics covered, we can start with the actual application! This is what I have in mind… The main view (which I called the Dashboard offers shortcuts to some of the main capabilities of 7MC, like videos, pictures, music and TV). I also allow you to change the volume (up, down, mute and un-mute). Here is the dashboard:

Once you have actually clicked on option, you will be taken to another view.

This is the direction pad. Navigation is done using simple gestures (Flick up/down/left/right and double-tap).

Here is the code to check for gestures:

C#
private</span /> void</span /> PhoneApplicationPage_ManipulationStarted
	(object</span /> sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
    e.Handled = true</span />;
}

private</span /> void</span /> PhoneApplicationPage_ManipulationDelta
	(object</span /> sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
}

private</span /> void</span /> PhoneApplicationPage_ManipulationCompleted
	(object</span /> sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
    double</span /> x = e.TotalManipulation.Translation.X;
    double</span /> y = e.TotalManipulation.Translation.Y;

    //</span /> Ugly hack I know...
</span />    var</span /> vm = DataContext as</span /> MainViewModel;

    if</span /> (Math.Abs(y) > Math.Abs(x))
    {
        if</span /> (y < -20)
        {
            vm.MceService.Button("</span />up"</span />);
        }
        if</span /> (y > 20</span />)
        {
            vm.MceService.Button("</span />down"</span />);
        }
    }
    else</span />
    {
        if</span /> (x < -20)
        {
            vm.MceService.Button("</span />left"</span />);
        }
        if</span /> (y > 20</span />)
        {
            vm.MceService.Button("</span />right"</span />);
        }
    }
}

Very basic, I know… but it works. :)

And as always, here is the code.

Before you start, check out this video:

Also read:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here