1

developing Web app for gear s2, I am trying to play next/previous audio file when bezel is rotated clockwise/counterclockwise.

just like the "Music Player" on the watch.

what I tried so far is as follows, but only the second song plays when I rotate the bezel clockwise and when I rotate CCW, only the first song plays. I don't know how to write it so that EACH time that I rotate the bezel, it goes to the next song.

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

Hopefully someone can find out what the problem is or if there is another way to do it. Thank you.

4

1 回答 1

1

对于任何有这个问题的人,我终于发现了问题所在。您必须向页面添加一个 EventListener,如下所示:

page.addEventListener("pagebeforeshow", function() {

// 做一点事

});

于 2015-12-02T10:54:43.573 回答