[英]Add music to windows 8.1 app - Visual studio 2013
I'm creating a windows app , windows 8.1 app, using visual studio 2013. 我正在使用Visual Studio 2013创建Windows应用程序Windows 8.1应用程序。
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. 两者都将设置一个MediaElement来运行您要播放的音乐文件。
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. 由于MediaElement仅在它在视觉树中时才播放,因此您需要玩一个小技巧以使其在应用程序的所有页面中运行:不要在顶层页面之外运行该应用程序,而应使用MediaElement创建一个根页面和子框架,然后在子框架之外运行应用程序的页面。 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. 要在应用程序处于后台时播放音乐,您需要声明后台音频任务,将MediaElement设置为BackgroundCapableMedia,然后连接SystemMediaTransportControls。 See the How to play audio in the background documentation on MSDN for details. 有关详细信息,请参见MSDN上的后台文档中的 “ 如何播放音频” 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.