After purchasing a device around 3 weeks ago I have now registered as a developer and I now have the ability to deploy applications to my device.
I thought I should revisit some of my previous WP7Dev related postings, one being WP7 and Microsoft.Xna.Framework.Audio.Microphone.
After creating a new project for this sample code and running it I was presented with the following error :-
"FrameworkDispatcher.Update has not been called. Regular FrameworkDispatcher.Update calls are necessary for fire and forget sound effects and framework events to function correctly. See http://go.microsoft.com/fwlink/?LinkId=193853 for details."
After a search I found the following blog post which solved the issue :-
Recording Audio in Silverlight on Windows Phone 7
Friday, 10 December 2010
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
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.
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();
}
}
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
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.
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.
Sunday, 17 January 2010
Finding an Appointment from the POOM AppointmentCollection
An interesting question was asked on the MSDN forums regarding the retrieval of an Appointment from the POOM AppointmentCollection. The question was related to the performance of such an operation when the AppointmentCollection contained a large number of Appointments. Three proposed approaches where listed however did not provide the performance the user was looking for.
Having read the question and thought about the problem I had an idea about how this problem could be solved. My idea was a "Divide and Conquer" routine. The basic idea behind this routine is that the problem is split into smaller and smaller pieces until the problem is solved. This can be applied to the AppointmentCollection problem in the following way.
From querying the count of items in the AppointmentCollection you know the index of the first item (0) and the last item (the count of items), therefore you can calculate the half way point between these two numbers. The Appointment that corresponds to this half way point is retrieved and its date compared against the date we are searching for. If the date of the queried appointment is less than the date we are searching for then we know that the appointment we are searching for is between the half way point and the last item (the count of items).
In the next iteration the next half way point is calculate using the previous half way point and the last item (the count of items), the appointment is queried and if the appointment date is now greater than the date we are searching for then we know that the appointment must be within the first half of the appointments.
This process continues until the appointment is found.
For my tests I used a range of appointments from the 01/01/2009 to 31/12/2010 (720 Appointments). The test was running on the USA Windows Mobile 5.0 Pocket PC R2 Emulator.
Using a Foreach approach on the AppointmentCollection :-
Time Taken (Average) : 7389ms - Appointments Checked : 382
Using a "Divide and Conquer" approach on the AppointmentCollection :-
Time Taken (Average) : 222ms - Appointments Checked : 12
As you can see there is a great improvement gained from using the "Divide and Conquer" approach.
The source code for this approach is at the following location :-
http://www.smartmobiledevice.co.uk/Projects/FasterAppSearchSample.zip
Having read the question and thought about the problem I had an idea about how this problem could be solved. My idea was a "Divide and Conquer" routine. The basic idea behind this routine is that the problem is split into smaller and smaller pieces until the problem is solved. This can be applied to the AppointmentCollection problem in the following way.
From querying the count of items in the AppointmentCollection you know the index of the first item (0) and the last item (the count of items), therefore you can calculate the half way point between these two numbers. The Appointment that corresponds to this half way point is retrieved and its date compared against the date we are searching for. If the date of the queried appointment is less than the date we are searching for then we know that the appointment we are searching for is between the half way point and the last item (the count of items).
In the next iteration the next half way point is calculate using the previous half way point and the last item (the count of items), the appointment is queried and if the appointment date is now greater than the date we are searching for then we know that the appointment must be within the first half of the appointments.
This process continues until the appointment is found.
For my tests I used a range of appointments from the 01/01/2009 to 31/12/2010 (720 Appointments). The test was running on the USA Windows Mobile 5.0 Pocket PC R2 Emulator.
Using a Foreach approach on the AppointmentCollection :-
Time Taken (Average) : 7389ms - Appointments Checked : 382
Using a "Divide and Conquer" approach on the AppointmentCollection :-
Time Taken (Average) : 222ms - Appointments Checked : 12
As you can see there is a great improvement gained from using the "Divide and Conquer" approach.
The source code for this approach is at the following location :-
http://www.smartmobiledevice.co.uk/Projects/FasterAppSearchSample.zip
Subscribe to:
Posts (Atom)