如何在 Gear s2 中使用挡板播放 next/previous 音频文件?
How to play next/previous audio file using bezel in Gear s2?
正在为 gear s2 开发 Web 应用程序,我正在尝试在旋转边框时播放 next/previous 音频文件 clockwise/counterclockwise。
就像手表上的"Music Player"一样。
目前我试过如下,顺时针旋转表圈时只播放第二首歌曲,逆时针旋转时仅播放第一首歌曲。
我不知道如何写它,以便每次旋转表圈时,它都会转到下一首歌曲。
var audio = new Audio();
var source = ["songs/coldplay.mp3", "songs/abba.mp3", "songs/goodbye.mp3", "songs/sleep.mp3"];
var i = 0;
var current = null;
rotaryDetentHandler = function(e) {
direction = e.detail.direction;
if (direction === "CW") {
if(i <source.length)
i++;
else i=source.length;
}
if (direction === "CCW") {
if(i>0)
i-- ;
else i = 0;
}
if(current !=null)
{stop();}
audio.src = source [i];
audio.load();
audio.play();
current = audio;
}
function stop()
{
current.pause();
}
希望有人能找出问题所在,或者是否有其他方法可以解决。
谢谢。
对于遇到此问题的任何人,我终于找到了问题所在。
您必须向页面添加一个 EventListener,如下所示:
page.addEventListener("pagebeforeshow", 函数() {
// 做点什么
});
正在为 gear s2 开发 Web 应用程序,我正在尝试在旋转边框时播放 next/previous 音频文件 clockwise/counterclockwise。
就像手表上的"Music Player"一样。
目前我试过如下,顺时针旋转表圈时只播放第二首歌曲,逆时针旋转时仅播放第一首歌曲。 我不知道如何写它,以便每次旋转表圈时,它都会转到下一首歌曲。
var audio = new Audio();
var source = ["songs/coldplay.mp3", "songs/abba.mp3", "songs/goodbye.mp3", "songs/sleep.mp3"];
var i = 0;
var current = null;
rotaryDetentHandler = function(e) {
direction = e.detail.direction;
if (direction === "CW") {
if(i <source.length)
i++;
else i=source.length;
}
if (direction === "CCW") {
if(i>0)
i-- ;
else i = 0;
}
if(current !=null)
{stop();}
audio.src = source [i];
audio.load();
audio.play();
current = audio;
}
function stop()
{
current.pause();
}
希望有人能找出问题所在,或者是否有其他方法可以解决。 谢谢。
对于遇到此问题的任何人,我终于找到了问题所在。 您必须向页面添加一个 EventListener,如下所示:
page.addEventListener("pagebeforeshow", 函数() {
// 做点什么
});