我今晚一直试图让背景音频工作很长时间!显示的音频标签“msAudioCategory”的HTML5属性不是有效的。这很奇怪,我无法在任何地方找到这个问题的帮助。
如果我不明白你的答案,请原谅我。 我的default.js(在随机点开始使其缩短):
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state
// that needs to persist across suspensions here. You might use the
// WinJS.Application.sessionState object, which is automatically
// saved and restored across suspension. If you need to complete an
// asynchronous operation before your application is suspended, call
// args.setPromise().
// Declare a variable that you will use as an instance of an object
var mediaControls;
// Assign the button object to mediaControls
mediaControls = Windows.Media.MediaControl;
// Add an event listener for the Play, Pause Play/Pause toggle button
mediaControls.addEventListener("playpausetogglepressed", playpausetoggle, false);
mediaControls.addEventListener("playpressed", playbutton, false);
mediaControls.addEventListener("pausepressed", pausebutton, false);
mediaControls.addEventListener("stoppressed", stop, false);
// The event handler for the play/pause button
function playpausetoggle() {
if (mediaControls.isPlaying === true) {
document.getElementById("playback").pause();
} else {
document.getElementById("playback").play();
}
}
// The event handler for the pause button
function pausebutton() {
document.getElementById("playback").pause();
}
// The event handler for the play button
function playbutton() {
document.getElementById("playback").play();
}
// The event handler for the stop button
function stop() {
document.getElementById("playback").pause();
document.getElementById("playback").currentTime = 0;
}
};
app.start();
}
()
);
元素标记:
<audio id="audtag" autoplay="autoplay" msAudioCategory="BackgroundCapableMedia" src="http://-Hidden-:8000/;">
</audio>
我很确定我已经正确配置了所有内容。我确定我有背景功能或设置的东西。但是,它仍然说音频元素属性'msAudioCategory'不是有效的HTML5。我在哪里将JavaScript放在default.js中来定义该属性?在app.start()之后?文件中的文档让我感到困惑。
第一次制作应用程序总是很容易!
答案 0 :(得分:0)
你在app manifest中设置了正确的声明吗? 您需要添加后台任务并将任务类型设置为音频和控制通道。
我昨天在C#样本上做了这个