0

I have a StorageFile instance in the foreground refers to a music file. I want to play it in the BackgroundAudioTask but the problem is:

make sure you define all objects to set their source in the background process only. The system will throw an InvalidCastException if your app tries to set a source other than a URI in the foreground process.

  • I can't pass file path and then reload it from storage in the background using StorageFile.GetFileFromPathAsync because my app may not have access to it (a shared file from another app internal storage).

The Only solution comes to my mind is to pass the same StorageFile object to background, but don't know how to do it since they are on different threads.

So how to play a file in the background?

(It's a windows phone runtime app)

user3646098
  • 299
  • 3
  • 14
  • Have you tried to pass the whole `StorageFile` object to the background player in a `ValueSet` using [SendMessageToBackground](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.media.playback.backgroundmediaplayer.sendmessagetobackground.aspx)? It seems like Windows Phone 8.1 Runtime should do all the marshalling internally so you get the same object in the background player. – Alovchin Aug 15 '14 at 09:50
  • @Alovchin it only gets strings as a massage – user3646098 Aug 16 '14 at 10:51
  • Seems so. Have you tried setting the URI of the file (that is, file's path) in the foreground? It is said in the quote you mentioned that you can do this. Other than that, you could try copying the StorageFile into the local storage of your app and then pass its path inside local storage. – Alovchin Aug 16 '14 at 14:42

0 Answers0