今天晚上我一直在努力让背景音频正常工作!音频标签的 HTML5 属性“msAudioCategory”似乎是无效的。这很奇怪,我在任何地方都找不到这个问题的帮助。
如果我不明白你的答案,请先原谅我。我的 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() 之后?文件中的文档让我感到困惑。
第一次制作应用程序总是应该很容易!