Overview
I need to include a podcast player in the app I'm writing, so I decided to write a prototype app to demo the Windows 8 audio capabilitiesSource here: https://bitbucket.org/webbercross/win8audioplayer/
Features
I wanted to include the following:- Background capabilities
- Live tile glyph updates
- A custom re-templatable control
- Hardware interaction
- Fully working demo with all required tasks
Background Audio
I've previously use the Background Audio Agent in WP7 and was expecting something similar. There's no direct equivalent but the MediaElement is Windows 8 provides new features different to Silverlight. The new MediaElement has an 'AudioCategory' attribute which can be set to 'BackgroundCapableMedia' to allow it to continue playing while the page is not active or when the app is suspended, but not closed.
<MediaElement x:Name="mediaElement" AudioCategory="BackgroundCapableMedia" AutoPlay="False"/>
The manifest needs modifying to have a Background declaration with 'Audio' and 'Control channel' properties:
Additionally, a wide tile must be used.
Live Tile Glyph Updates
I wasn't sure at first if this was done automatically by the task, but it's not, it needs doing manually, so I wrote a helper class to do it:
public enum Glyphs
{
none,
activity,
alert,
available,
away,
busy,
newMessage,
paused,
playing,
unavailable,
error,
attention,
}
public class BadgeHelper
{
public static void UpdateBadge(Glyphs glyph)
{
// Get badge xml content
var content = BadgeUpdateManager.GetTemplateContent(Windows.UI.Notifications.BadgeTemplateType.BadgeGlyph);
var element = content.GetElementsByTagName("badge")[0];
// Set new glyph value
element.Attributes[0].NodeValue
= glyph.ToString();
// Update badge
var notification = new
BadgeNotification(content);
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(notification);
}
}
Normal tile:
Tile with play glyph:
Custom Template
This is the same as Silverlight and WPF, I put in some visual states for play and paused mode. The template is in the default Templates\Generic.xaml location.
Hardware Interaction
The MediaControl object has a number of events which can be subscribed to.
The Demo
[Edit] The demo is now finished, enjoy!
No comments:
Post a Comment