2

I am building a Windows Phone 8.1 RT App which runs MP3 files in Background task.

I followed the steps in the sample code shown here : http://code.msdn.microsoft.com/windowsapps/BackgroundAudio-63bbc319

When the app runs in the background, I would like to show the Album Artist & Song Title. Currently it just shows the file name.

enter image description here

Saqib Vaid
  • 412
  • 6
  • 23

1 Answers1

2

In SampleBackgroundAudioTask, there is a MyBackgroundAudioTask which is the background audio task used for playing music. There's an object of type SystemMediaTransportControls in that class called systemmediatransportcontrol.

SystemMediaTransportControls class enables your app to use the system media transport controls provided by Windows and update the media info that is displayed. There's a private method in MyBackgroundAudioTask responsible for updating the UVC (Universal Volume Control) when current track changes called UpdateUVCOnNewTrack. This uses the SystemMediaTransportControls.DisplayUpdater to set the MusicProperties. MusicProperties is of type MusicDisplayProperties and include properties such as the song title and the song artist.

This is how you set the song title and artist which gets shown in the UVC.

systemmediatransportcontrol.DisplayUpdater.MusicProperties.Title = "My lovely track";
systemmediatransportcontrol.DisplayUpdater.MusicProperties.Artist = "An awesome artist";
systemmediatransportcontrol.DisplayUpdater.Update();
Igor Ralic
  • 14,975
  • 4
  • 43
  • 51
  • Is it possible to show the Media tags directly from the MP3 file, instead of having to explicitly setting it? – Saqib Vaid Aug 18 '14 at 03:29
  • Your answer works, but just wondering if I could be picked up from the tags defined on my MP3 file so I don't have to worry about setting it. – Saqib Vaid Aug 18 '14 at 05:48
  • @SaqibVaid I think there's a way to read MusicProperties from a file - http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.musicproperties – Igor Ralic Aug 18 '14 at 11:11
  • Thanks. I figured out that I could something like StorageFile storageFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Media\XYZ.mp3"); //Get file name here await systemmediatransportcontrol.DisplayUpdater.CopyFromFileAsync(MediaPlaybackType.Music, storageFile); systemmediatransportcontrol.DisplayUpdater.Update(); – Saqib Vaid Aug 18 '14 at 11:28
  • is it possible to sett the values from the foreground app. because i am trying but isn't working ? – Hager Aly Dec 01 '16 at 15:18