IT tutorials
 
Technology
 

Windows Phone 8 : Coordinating Background Audio Playback (part 1) - Background Audio Player

3/1/2014 7:56:54 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Windows Phone allows you to create apps that respond to the Universal Volume Control (UVC) on the phone and, in conjunction with an onscreen menu, coordinate the playback of audio, even when your app is not running in the foreground.

1. Background Agent Recap

Windows Phone supports the following three types of BackgroundAgents:

- ScheduledTaskAgent

- AudioPlayerAgent

- AudioStreamingAgent

Background agents are classes invoked by the OS at certain times to carry out activities in the background (from another process) while your app may not be running in the foreground.

2. Background Audio Overview

The following compose the three main classes used for background audio:

BackgroundAudioPlayer

AudioPlayerAgent

AudioStreamingAgent

BackgroundAudioPlayer is a class that allows you to specify an audio file for playback and to carry out playback activities such as play, pause, fast-forward, and rewind. BackgroundAudioPlayer allows you to specify track information, such as the title of the track and its location. The built-in playback capabilities of the BackgroundAudioPlayer allow audio files to be streamed from either a remote server, or locally, from isolated storage.

Out of the box, BackgroundAudioPlayer supports playback formats such as MP3, WMA, and WAV. For a complete list of supported audio formats, see http://bit.ly/pnnT8C. BackgroundAudioPlayer offers little in the way of coordinating the playback of a list of audio tracks. This is the task of the AudioPlayerAgent.

AudioPlayerAgent classes are specialized agents used to retrieve audio files and coordinate the playback of background audio via the BackgroundAudioPlayer. AudioPlayerAgent provides a number of method callbacks that are automatically called by the OS based on user actions.

An AudioStreamingAgent can be used to customize how audio data is procured by your BackgroundAudioPlayer. You can supplant the BackgroundAudioPlayer’s media sourcing capabilities by providing your own logic to download and decode an audio file.

3. Background Audio Player

The BackgroundAudioPlayer class implements the singleton pattern. The single instance of the BackgroundAudioPlayer is accessed in your foreground app via its static Instance property, as shown:

BackgroundAudioPlayer.Instance.Track
    = new AudioTrack(
             new Uri("http://example.com/Audio.mp3", UriKind.Absolute),
             "Track Name", "Artist", "Album", null);
BackgroundAudioPlayer.Instance.Play();

The behavior of the BackgroundAudioPlayer changes depending on whether it is being used in your foreground app or from an AudioPlayerAgent. When the BackgroundAudioPlayer is used in your foreground app, all calls are relayed to your AudioPlayerAgent. When used from an AudioPlayerAgent, the BackgroundAudioPlayer affects the playback of audio directly. Without an AudioPlayerAgent, the BackgroundAudioPlayer does nothing.

This dual behavior can be best understood by looking at the internal workings of the BackgroundAudioPlayer. The BackgroundAudioPlayer is a proxy that relies on a native implementation of an internal IAudioPlaybackManager interface. When the BackgroundAudioPlayer is used in your foreground app, the IAudioPlaybackManager relays all audio requests to the app’s AudioPlayerAgent. Conversely, when used from your AudioPlayerAgent, the IAudioPlaybackManager uses the native audio playback system instead.

BackgroundAudioPlayer contains several public methods that allow you to control the playback of audio (see Table 1).

TABLE 1. BackgroundAudioPlayer Audio Playback Related Methods

Image

BackgroundAudioPlayer contains several public audio playback-related properties, which are shown in Table 2.

TABLE 2. BackgroundAudioPlayer Audio Playback-Related Properties

Image

BackgroundAudioPlayer contains a principle event, PlayStateChanged, which is used to detect, for example, when a track begins playing.

New in Windows Phone 8 is the capability to retrieve the current play state and preceding play state from the PlayStateChangedEventArgs. For compatibility with Windows Phone 7.1 OS, the signature of the PlayStateChanged event has not changed in the Windows Phone SDK. Therefore, to retrieve the play states, you must cast the EventArgs argument to a PlayStateChangedEventArgs object, as shown in the following example:

void HandlePlayStateChanged(object sender, EventArgs e)
{
    /* New in Windows Phone 8, the current and previous playstate
     * can be retrieved using the PlayStateChangedEventArgs. */
    PlayStateChangedEventArgs args = (PlayStateChangedEventArgs)e;
    PlayState currentPlayState = args.CurrentPlayState;
    PlayState previousPlayState = args.IntermediatePlayState;
    ...
}

 
Others
 
- Microsoft Exchange Server 2013 : Site mailboxes (part 3) - The life cycle of site mailboxes, Site mailbox provisioning policy
- Microsoft Exchange Server 2013 : Site mailboxes (part 2) - How site mailboxes work - Synchronization between Exchange and SharePoint
- Microsoft Exchange Server 2013 : Site mailboxes (part 1) - How site mailboxes work
- Microsoft Exchange Server 2013 : Migration to modern public folders
- Microsoft Exchange Server 2013 : Migration to modern public folders
- Windows 8 : Using Secure Boot and SmartScreen Filter
- Windows 8 : Configuring network discovery and wireless security (part 2)
- Windows 8 : Configuring network discovery and wireless security (part 1) - Creating network discovery profiles
- Sharepoint 2013 : Search for People (in SharePoint Server)
- Sharepoint 2013 : Use the Advanced Search (in SharePoint Server)
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us