[Download Code]
In a special holiday post my gift to you is not one, not 2, but 3 windows phone camera tricks. It’s a mobile ménage à trois.
1,,) Flashlight
There are lots of those flashlight apps in the marketplace that take about 2 minutes to build. This also took 2 minutes to build but it’s way better because it uses the real light on your phone. (Note: It’s turning on camera recording, but not actually saving anything when it’s done. Not sure what that will do to memory usage if you wonder through a cave with this as your flashlight. Might need to turn it off occasionally)
2) Barcode Scanning
Uses zxing. There was a Silverlight port linked somewhere that I used. Seems to work well for QR codes. Not so well for other stuff. The code in there right now should just work. You can use zxing generator to test it out. I’d like to get the 1D barcode scanning to work, but I didn’t have time to see what’s the problem right now.
3) Augmented Reality
Uses the awesome SLARToolkit by René Schulte. Basically his hello world augmented reality app running on the phone. You can use this marker to test it out.
You should just be able to run the xap in the debug folder to try all of this out. The code is all pretty simple, but a few people have asked about barcode scanning and AR so this should get you started.
If you want to build yourself you need to do a few things since I put the Microsoft.Phone.Media.Extended dll in the GAC.
1. Copy Microsoft.Phone.Media.Extended.dll to C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0ProfileWindowsPhone
2. Open C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0ProfileWindowsPhoneRedistList FrameworkList.xml and add the line
3. Open a visual studio command prompt and go to C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0ProfileWindowsPhone and type “sn -Vr Microsoft.Phone.Media.Extended dll”
Obviously you’ll need a copy of the Microsoft.Phone.Media.Extended dll. You can get that from the rom on your phone or from a rom that someone else dumped.
If you want to build your own app using the camera, make sure to add to the capabilities in the manifest.
Also I think I contractual obligated to say this, but using the camera in this manner will not pass marketplace certification unless you also include a healthy bribe with your xap.
,
permalink
Motion is a key part of WP7 application development. Without motion, the WP7 UI is just a bunch of text. Not nearly as exciting. To delight users, you can add some transitions between pages. The sample app includes some storyboards to animate between two pages. Other people have noted that you can just use the transitioning content control form the SIlverlight toolkit. Peter Torr also had a nice animating frame control in his mix demo code (his blog has some other great code samples for WP7 app dev). I took some of those concepts and the code from the TransitioningContentControl to make a new animating frame control.
In this prototype, the frame takes a snapshot of the old content and the new content using writeable bitmaps and animates the snapshots and then replaces those with the actual page. The benefit is smoother animation on pages with lots of controls. Otherwise, if you have a large panorama, it might not animate that cleanly. Like the other solutions based on the TransitioningContentControl, you can centralize all the animations in one place and not have to handle them on each individual page. Peter’s code also had a nice snippet for choosing the animation based on the navigation direction so you could just have a forward / backward animation and not have to do anything on each page.
You could also probably add some more advanced transitions using pixel shaders or make an default no transition state if you wanted to have some specific animation on a page where individual controls transitioned out differently like some of the WP7 shell apps.
Sample Code – 100% guaranteed to work on my emulator
,
permalink
At some point in the future it will be awesome when you can just tell your computer what to do and it does it – without typing to help those of us with a blistering 11 WPM hunk and peck technique. Siri, a mobile digital assistant using speech recognition was voted best tech at SXSW. I don’t know about that one. Although, I’m sure it will get better when Apple rebuilds it and bundles on iPhone 5. So how would you do that on WP7? There have been some videos floating around showing Bing with some voice control so obviously the phone has speech recognition. So what options are there:
- System.Speech? Not included in WP7/SL
- Nuance software like Siri? No WP7/SL version yet.
- Invoking the SAPI dlls on the phone? No automation factory in WP7 SL.
- Web services using System.Speech and mic on the phone? YES!
The last one was my least favorite but that works for now.
I built a quick sample app to show how to do text-to-speech and speech recognition on WP7.
@eklimczak will not be happy with the developer designed UI.
In this sample there is web service with provides access to the system.speech APIs in .NET. Basically it’s just passing around byte arrays. On the phone it’s using the XNA audio frameworks to play the text-to-speech stream and to record using the microphone. The code is pretty simple and you can download from the link at the end of this post. The only things to note are adjusting the WCF config to handle larger byte uploads and the Microphone API is a little weird with that 1 second buffer. It would be nice if you could just to mic.start and mic.end which would return an array of bytes instead of managing your own stream inside the buffer ready callback.
Couple of downsides to this approach:
- Recoding from the phone has some static. Could be my code or the my mic is bad / not calibrated right.
- Having to make web service calls instead of local access is not ideal (Microsoft, please add an API for the SAPI dlls) Although in the context of an app like Siri it’s not so bad since you need to do web service lookups to get data back
- Speech recognition quality really depends on either a,,) a limited grammar set like that pizza grammar in the sample or b) training the recognizer. For the latter it would be annoying to have users train the system. Using the System.Speech stuff you’d have to have a profile for each user.
So until Microsoft adds some speech client APIs on the phone or Nuance releases a wp7 product, this is a decent workaround. In the future I’d like to build something similar to Siri. I shall call it Iris in homage. I’m a big fan of mobile speech apps because frankly it’s just not safe to Google while driving.
Since some of my designer co-workers have been posting UI sketches for WP7, I’d like to start posting some code prototypes for things I try out on the phone. That will probably last 2 weeks, but for the moment I have like 10 posts in the queue.
Sample Code – 100% guaranteed to work on my emulator
,
permalink