Windows 8音频在后台播放

编程入门 行业动态 更新时间:2024-10-27 22:22:17
本文介绍了Windows 8音频在后台播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经阅读了以前关于此的帖子和microsoft的文档,但似乎无法让我的应用程序在后台运行Sound。它播放100%但是当应用程序暂停时,音乐也会停止。我添加了后台任务声明选择音频,我的音频标签看起来像这样

I have read previous posts on this and documents by microsoft but cannot seem to get my app to run Sound in the background. It plays 100% but when ever the app is then suspended the music also stops. I have added "Background Tasks" declarations selecting Audio and my audio tag looks like this

<audio id="musicplayr" msAudioCategory="BackgroundCapableMedia" controls="controls"><source src="song.mp3"/> </audio

最后我的javascript包含对MediaControls的引用

and finally my javascript includes the references to MediaControls

var MediaControls = Windows.Media.MediaControl; // Add event listeners for the buttons MediaControls.addEventListener("playpressed", play, false); MediaControls.addEventListener("pausepressed", pause, false); MediaControls.addEventListener("playpausetogglepressed", playpausetoggle, false); // Add event listeners for the audio element document.getElementById("musicplayr").addEventListener("playing", playing, false); document.getElementById("musicplayr").addEventListener("paused", paused, false); document.getElementById("musicplayr").addEventListener("ended", ended, false);

及以下代码我有事件处理程序

and below in the code i have the event handlers

// Define functions that will be the event handlers function play() { document.getElementById("musicplayr").play(); } function pause() { document.getElementById("musicplayr").pause(); } function playpausetoggle() { if(MediaControls.isPlaying === true) { document.getElementById("musicplayr").pause(); } else { document.getElementById("musicplayr").play(); } } function playing() { Windows.Media.MediaControl.isPlaying = true; } function paused() { Windows.Media.MediaControl.isPlaying = false; } function ended() { Windows.Media.MediaControl.isPlaying = false; }

*注意musicplayr是html5标签的参考

*Note musicplayr is the reference for the html5 tag

任何帮助都理解为什么这不起作用?

Any help appreciated why this is not working?

推荐答案

你还需要一个事件处理程序停止的事件。如果没有四个处理程序中的任何一个 - playpressed,pausepressed,playpausetogglepressed和stoppressed - 将不会启用背景音频。请参阅 http:// social。 msdn.microsoft/Forums/en-IN/winappswithhtml5/thread/2ca0c122-df31-401c-a444-2149dd3e8d68 在MSDN论坛上引发了同样的问题。

You also need an event handler for the stoppressed event. Without any of the four handlers--playpressed, pausepressed, playpausetogglepressed, and stoppressed--background audio won't be enabled. See social.msdn.microsoft/Forums/en-IN/winappswithhtml5/thread/2ca0c122-df31-401c-a444-2149dd3e8d68 on the MSDN forums where the same problem was raised.

.Kraig

更多推荐

Windows 8音频在后台播放

本文发布于:2023-11-27 03:19:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   音频   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!