0

I am working on wondows mango app and I have two XAML pages(say page1 and page2). On page1 I have a playlist and on page2 I have a media element that plays the song selected on page1, now what I want is to keep song playing in background as user switches between pages. I got a few links that keep song playing when app gets in background but not when a page is closed(by clicking back button).

How can I achieve this, all suggestions, pointers are welcome.

Thanks, Ravi Gupta - :( newbie at windows phone

Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
TechnicalSmile
  • 1,387
  • 5
  • 16
  • 30

2 Answers2

0

You'll want to use the BackgroundAudioPlayer for this. MSDN has a complete sample for playing audio in the background. You can download their sample from here. You can add a project to you application to handle processing background audio (if you need the audio to play after the app closes) or you can handle it all within the application itself my subscribing to the PlayStateChanged event. From the event you can set the next track.

Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
  • Thanks shawn. Can it also play DRM protected files? – TechnicalSmile Jul 03 '12 at 07:51
  • I've never tried DRM audio. Can you please post back your results? – Shawn Kendrot Jul 03 '12 at 08:35
  • It doesn't works for DRM files. Gives me error saying "file not found at specified location" in method 'PlayTrack' of AudioPlayer class in sample project you suggested. I have tried changing DRM file properties(Build Action) and copy to output directory, but nothing helped. Any pointers? – TechnicalSmile Jul 03 '12 at 09:07
  • Are you saving the song to IsoStore? Can you get the regular songs to play? – Shawn Kendrot Jul 03 '12 at 15:47
  • yes I am saving songs to IsoStore and also regular songs play well, problem is only with DRM protected files. File not found resolved after I changed an entry in host file of windows. But now its giving problems while reading DRM file to get them stored in Iso Storage. I feel this is not possible to be done with background agent after I saw this link: http://msdn.microsoft.com/en-us/library/hh202962%28v=vs.92%29.aspx – TechnicalSmile Jul 04 '12 at 06:39
0

You can also use XNA's MediaPlayer() See: https://stackoverflow.com/a/11385865/1510036

Community
  • 1
  • 1
naqvitalha
  • 793
  • 5
  • 9