IT tutorials
 
Technology
 

Windows Phone 8 : AudioPlayerAgent Sample (part 4) - Controlling Background Audio from Your Foreground App - Monitoring Playback Progress

3/1/2014 8:06:07 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Monitoring Playback Progress

The viewmodel contains a Position property that reflects the progress of the current AudioTrack. Because the BackgroundAudioPlayer does not have facility to monitor the progress of a track directly, the viewmodel uses a Timer to periodically raise a property changed event for the Position property. The tick handler is shown in the following excerpt:

void HandleTimerTick(object state)
{
    if (player.PlayerState == PlayState.Playing)
    {
        OnPropertyChanged(() => Position);
    }
}

When a Position property change is detected in the view, it prompts a Slider control to reread the property. The Position get accessor calculates the position value, which is returned as a value between 0 and 1, as shown:

public double Position
{
    get
    {
        if (player.Track == null || player.Track.Duration.TotalSeconds < 1)
        {
            return 0;
        }
        double result = player.Position.TotalSeconds
                            / player.Track.Duration.TotalSeconds;
        return result;
    }
    set
    {
        if (player.Track != null)
        {
            double newSeconds = player.Track.Duration.TotalSeconds * value;
            TimeSpan newPosition = TimeSpan.FromSeconds(newSeconds);
            player.Position = newPosition;
        }
        OnPropertyChanged(() => Position);
    }
}

Raising a property changed event for the Position property causes the Slider, which is bound to the property, to be updated. The Slider is defined like so:

<Slider Value="{Binding Position, Mode=TwoWay}" Minimum="0" Maximum="1" />

Figure 3 shows the MainPage with the slider indicating the progress of the current track and the application bar icon buttons for controlling playback.

Image

FIGURE 3 A user interface to control the BackgroundAudioPlayer from a foreground app.

Numerous possibilities exist for extending an app such as this. For example, it could be extended to include a view for the playlist or an image for the album art—the sky’s the limit!

 
Others
 
- Windows Phone 8 : AudioPlayerAgent Sample (part 3) - Controlling Background Audio from Your Foreground App - MainPageViewModel
- Windows Phone 8 : AudioPlayerAgent Sample (part 2) - AudioPlayerAgent Virtual Methods
- Windows Phone 8 : AudioPlayerAgent Sample (part 1)
- Windows Phone 8 : Coordinating Background Audio Playback (part 2) - Representing Audio Files with the AudioTrack Class, Creating a Custom Audio Player Agent
- Windows Phone 8 : Coordinating Background Audio Playback (part 1) - Background Audio Player
- 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
 
 
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