繁体   English   中英

Windows 8 App中的背景音频

[英]Background Audio in Windows 8 App

我正试图在Windows 8中让音频在应用程序之外工作(我正在使用HTML5,Javascript方法),所以当你关闭应用程序时,声音会继续工作,从我在这里和其他网站上研究过的我相信这是在Windows 8'背景音频中调用的,我已经按照Microsoft Developer网站上的所有教程,并在应用程序清单中声明了背景音频:

<Extension Category="windows.backgroundTasks" StartPage="default.html">
      <BackgroundTasks>
        <Task Type="audio" />
        <Task Type="controlChannel" />
      </BackgroundTasks>
    </Extension>

我已经将msAudioCategory =“BackgroundCapableMedia”controls =“controls”添加到我的HTML5音频标签中,如下所示:

<audio id="playback" msAudioCategory="BackgroundCapableMedia" controls="controls"> 
    </audio>

我还把它添加到我的default.js文件中,这个文件显而易见,虽然我不知道这是什么

// 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);

// 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();
}

我也尝试在最后一部分改变ID以获得一个哈希标签,但是当我按下开始按钮回家时音频停止,我做错了什么?

谢谢

我相信你还需要处理“停止”事件:

mediaControls.addEventListener("stoppressed", stop, false);

function stop() {
    // Handle the stop event.
    document.getElementById("playback").pause();
    document.getElementById("playback").currentTime = 0;
}

在Windows 8 JavaScript应用程序中播放背景音频的三个步骤是:

  1. package.appxmanifest中演示音频后台任务。 还列出一个StartPage 你这样做了。
  2. 设置msAudioCategory="BackgroundCapableMedia" 你这样做了
  3. 实施对媒体控制的支持。 媒体控件是遥控器上或播放,暂停或停止音频的某些键盘上的按钮。 有关工作示例,请参阅MSDN上的媒体示例配置密钥 除了你已经处理的3个事件之外,我只能处理“stoppressed”时才能使示例工作。

有关更多信息,请观看2011年Build会议中的Metro风格应用,视频和音频,第2部分 背景音频从视频开始约31分钟,20秒开始,持续约10分钟。 请注意,此视频是从2011年9月开始的,涵盖了Windows 8的开发人员预览版。这些概念仍适用于Windows 8和Windows RT的已发布版本,但名称空间和属性名称在某些地方有所不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM