Can you play a List continuously in the back

2019-08-19 03:10发布

问题:

I have a list of songs (List<Song>) and i want to play all the songs even if the application goes into the background or under the lock screen.

I cannot use a SongCollection and MediaPlayer.Play(SongCollection) because i cannot create a SongCollection object from a List<Song>.

Is there anyway i can play this list of songs in the background, one by one (MediaPlayer.Play()) or otherwise?

回答1:

The answer is right in the documentation for SongCollection class: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.songcollection.aspx

All of the collections, playlists, and queues returned by methods and properties in the Microsoft.Xna.Framework.Media namespace are immutable. You cannot add or remove objects from those collections or playlists. To create a custom 'playlist' of songs, games must maintain their own list of songs to play, and play those songs one at a time by calling MediaPlayer.Play.

The only thing you might be able to do is add a background audio agent to your app. More details on that here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx