C# Class BackgroundAudioTask.MyBackgroundAudioTask

Impletements IBackgroundTask to provide an entry point for app code to be run in background. Also takes care of handling UVC and communication channel with foreground
Inheritance: IBackgroundTask
Mostra file Open project: dotnetcurry/Windows10-UWP

Public Methods

Method Description
Run ( IBackgroundTaskInstance taskInstance ) : void

The Run method is the entry point of a background task.

Private Methods

Method Description
BackgroundMediaPlayer_MessageReceivedFromForeground ( object sender, MediaPlayerDataReceivedEventArgs e ) : void

Raised when a message is recieved from the foreground app

CreatePlaybackList ( IEnumerable songs ) : void

Create a playback list from the list of songs received from the foreground app.

Current_CurrentStateChanged ( MediaPlayer sender, object args ) : void
GetCurrentTrackId ( ) : Uri
GetTrackId ( MediaPlaybackItem item ) : Uri
OnCanceled ( IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason ) : void

Handles background task cancellation. Task cancellation happens due to: 1. Another Media app comes into foreground and starts playing music 2. Resource pressure. Your task is consuming more CPU and memory than allowed. In either case, save state so that if foreground app resumes it can know where to start.

PlaybackList_CurrentItemChanged ( MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args ) : void

Raised when playlist changes to a new track

SkipToNext ( ) : void

Skip track and update UVC via SMTC

SkipToPrevious ( ) : void

Skip track and update UVC via SMTC

StartPlayback ( ) : void

Start playlist and change UVC state

TaskCompleted ( BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args ) : void

Indicate that the background task is completed.

UpdateUVCOnNewTrack ( MediaPlaybackItem item ) : void

Update Universal Volume Control (UVC) using SystemMediaTransPortControl APIs

smtc_ButtonPressed ( SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args ) : void

This function controls the button events from UVC. This code if not run in background process, will not be able to handle button pressed events when app is suspended.

smtc_PropertyChanged ( SystemMediaTransportControls sender, SystemMediaTransportControlsPropertyChangedEventArgs args ) : void

Fires when any SystemMediaTransportControl property is changed by system or user

Method Details

Run() public method

The Run method is the entry point of a background task.
public Run ( IBackgroundTaskInstance taskInstance ) : void
taskInstance IBackgroundTaskInstance
return void