Today I’m going to introduce how to stream online audio and play it in the background through BackgroundTasks.
This blog is using to create basic windows 8.1 application, so you should be familiar with XAML and C#.
So Friend, Let’s start, how to stream online audio and play it with you application.
Now it’s time to move, how to play audio in the background.
To play audio in the background, declare the Audio background task and handle the SystemMediaTransportControls buttons.
Important: Windows 8.1 introduces the SystemMediaTransportControls class which replace the MediaControl class. You should use SystemMediaTransportControls in your app.
Step 1: Declare the background audio task
Step 2: Define the MediaElement and set the AudioCategory
The AudioCategory is a property on MediaElement, it’s using to either Communication or BackgroundCapableMedia.
Define and listen to the CurrentStateChanged event,
Now, we should initialize the SystemMediaTranspostControls, here is the method called InitializeTransportControls for that reason
And here is the code of ButtonPressed (systemControls_ButtonPressed) event handler, also it’ll include two methods PlayMedia(), and PauseMedia()