简体   繁体   中英

Add music to windows 8.1 app - Visual studio 2013

I'm creating a windows app , windows 8.1 app, using visual studio 2013.

i want to add a background music to it.

how to add it?

Do you mean music while the app is playing or music running when the app is in the background?

For both you'll set up a MediaElement running the music file you want to play.

Since the MediaElement will only play while it's in the visual tree you need to play a small trick to keep it running through all of the app's pages: instead of running the app out of a top-level page, create a root page with the MediaElement and a child frame, then run the app's pages out of the child frame. See my blog entry Frame of reference: keeping the music playing across pages for more details.

To play music when the app is in the background you'll need to declare the background audio task, set the MediaElement to BackgroundCapableMedia, and wire up SystemMediaTransportControls. See the How to play audio in the background documentation on MSDN for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM