Sunday 16 May 2010

WP7 and CivicAddressResolver

After having a play with some of the different namespaces and classes within a WP7 project, I tried the CivicAddressResolver.

The following code was taken from Mike Taulty's UK TechDays presentation :-

CivicAddressResolver resolver = new CivicAddressResolver();
GeoCoordinate location = new GeoCoordinate(40.71448, -74.00734);

resolver.ResolveAddressCompleted += (sender, args) =>
{
if (args.Error == null)
{
string line1 = args.Address.AddressLine1;
string line2 = args.Address.AddressLine2;
string city = args.Address.City;
}
};

resolver.ResolveAddressAsync(location);

Currently the ResolveAddress and ResolveAddressAsync methods are not implemented, as detailed in the following forum post :-
http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/110ed7a5-d734-4d5c-937d-f0a29334c7e8

WP7 and Microsoft.Devices.VibrateController

After having a play with some of the different namespaces and classes within a WP7 project, I tried the VibrateController.

Found that the maximum duration for a vibration is 5 seconds.

To start a vibration :-

Microsoft.Devices.VibrateController.Default.Start(TimeSpan.FromSeconds(5));

To stop a vibration :-

Microsoft.Devices.VibrateController.Default.Stop();

Looking forward to being able to test this on a real device.

Monday 10 May 2010

WP7 and Microsoft.Xna.Framework.Audio.Microphone

I was looking to try out the Microphone functionality as detailed by Peter Foot in the following blog post :-
http://mobileworld.appamundi.com/blogs/peterfoot/archive/2010/03/26/audio-recording-in-wp7.aspx

This is the code that I came up with :-

public partial class MainPage : PhoneApplicationPage
{
private Microphone currentMic = Microphone.Default;
private byte[] currentData;
private MemoryStream currentStream = new MemoryStream();

public MainPage()
{
InitializeComponent();

SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
}

private void m_BufferReady(object sender, EventArgs e)
{
currentMic.GetData(currentData);
currentStream.Write(currentData, 0, currentData.Length);
}

private void Start_Click(object sender, RoutedEventArgs e)
{
currentMic.BufferDuration = TimeSpan.FromMilliseconds(1000);
currentData = new byte[currentMic.GetSampleSizeInBytes(currentMic.BufferDuration)];
currentMic.BufferReady += new EventHandler(m_BufferReady);

currentMic.Start();
}

private void Stop_Click(object sender, RoutedEventArgs e)
{
currentMic.Stop();
currentStream.Close();
}

private void Play_Click(object sender, RoutedEventArgs e)
{
SoundEffect currentSoundEffect = new SoundEffect(currentStream.ToArray(), currentMic.SampleRate, AudioChannels.Mono);
currentSoundEffect.Play();
}
}

Saturday 8 May 2010

WP7 and Silverlight Toolkit

I was interested in trying the Page Transistions sample as detailed in the following blog post :-
http://www.slickthought.net/post/2010/04/26/Simplifying-Page-Transitions-in-Windows-Phone-7-Silverlight-Applications.aspx

However there was a bug with assemblies certificate security using the April Refresh of the Windows Phone 7 CTP, as detailed in the following blog post :-
http://www.manyniches.com/windows-phone/signed-assemblies-bug-in-the-windows-phone-tools-ctp-refresh/

The particular problem I was experiencing was also reported in the following forum post :-
http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/d64d771a-0ab0-42e6-8c19-3ede9c33f05a

It was reported that removing the certificate from the System.Windows.Controls.Layout.Toolkit assembly was still not solving the issue, therefore I tried the steps outlined in the previous blog post and my experience was as follows :-

1. The particular powershell script was not running - In the blog post it details that I had to run the "set-executionpolicy remotesigned" command however I also had to unblock the script file which also meant changing the permissions for that file for my particular user on my machine to allow this unblock to occur.

2. Once the assemblies certificate had been removed, the problem reported in the forum post was still occuring so had a look at the Bin directory of the particular project I was using and there were two other DLLs from the Toolkit :-
System.Windows.Controls.Toolkit.dll
System.Windows.Controls.Toolkit.Internals.dll

These other two DLLs also needed their certificates removing. After doing so, I then had to reference these additional two assemblies directly in my project so that they would be the versions that were used (originally I had only referenced the System.Windows.Controls.Layout.Toolkit assembly). After doing this I am now able to test the page transistion sample.

Hopefully others will find this useful.