我已经阅读了以前关于这个和微软文档的帖子,但似乎无法让我的应用程序在后台运行Sound。它播放100%但是当应用程序暂停时,音乐也会停止。我添加了“后台任务”声明选择音频,我的音频标签看起来像这样
<audio id="musicplayr" msAudioCategory="BackgroundCapableMedia" controls="controls"><source src="song.mp3"/> </audio
最后我的javascript包含对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);
代码中的及以下我有事件处理程序
// 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标签的参考
任何帮助都理解为什么这不起作用?
答案 0 :(得分:2)
您还需要一个用于stoppressed事件的事件处理程序。如果没有四个处理程序中的任何一个 - playpressed,pausepressed,playpausetogglepressed和stoppressed - 将不会启用背景音频。请参阅MSDN论坛上发生同样问题的http://social.msdn.microsoft.com/Forums/en-IN/winappswithhtml5/thread/2ca0c122-df31-401c-a444-2149dd3e8d68。
.Kraig