TiRemoteControl icon indicating copy to clipboard operation
TiRemoteControl copied to clipboard

eventlistener

Open julien9999 opened this issue 12 years ago • 3 comments

hi, i don't understand how to add an event on click play-pause media buttons. thanks in advance

julien9999 avatar Mar 29 '13 17:03 julien9999

Thanks for trying to use my module. How about the following code sample?

var Control = require('net.hoyohoyo.tiremotecontrol');
Control.addEventListener('remotecontrol', function(e) {
  Ti.API.debug('remote control event was fired!');
  switch (e.subtype) {
    case Control.REMOTE_CONTROL_PLAY_PAUSE:
      // code executing when clicked play-pause media button
      break;
  }
});

hoyo avatar Mar 31 '13 04:03 hoyo

hi, thanks for your reply, actually when I try to use multiple events like the PLAY event and the PAUSE event it doesnt do anything

Control.addEventListener('remotecontrol', function(e) { Ti.API.debug('remote control event was fired!'); switch (e.subtype) { case Control.REMOTE_CONTROL_PLAY: sound.play();

  break;
case Control.REMOTE_CONTROL_PAUSE:
    sound.pause();

} }); Date: Sat, 30 Mar 2013 21:28:17 -0700 From: [email protected] To: [email protected] CC: [email protected] Subject: Re: [TiRemoteControl] eventlistener (#1)

Thanks for tring to use my widget.

How about the following code sample?

var Control = require('net.hoyohoyo.tiremotecontrol'); Control.addEventListener('remotecontrol', function(e) { Ti.API.debug('remote control event was fired!'); switch (e.subtype) { case Control.REMOTE_CONTROL_PLAY_PAUSE: // code executing when clicked play-pause media button break; } });

— Reply to this email directly or view it on GitHub.

julien9999 avatar Mar 31 '13 12:03 julien9999

I see that you want to do. You may receive REMOTE_CONTROL_PLAY_PAUSE event and use flag playing or not.

var isPlaying = false;
var Control = require('net.hoyohoyo.tiremotecontrol');
Control.addEventListener('remotecontrol', function(e) {
  Ti.API.debug('remote control event was fired!');
  switch (e.subtype) {
    case Control.REMOTE_CONTROL_PLAY_PAUSE:
      if (isPlaying) {
        // code executing when clicked play-pause media button on playing
      } else {
        // code executing when clicked play-pause media button before playing
      }
      isPlaying != isPlaying;
      break;
  }
});

hoyo avatar Mar 31 '13 13:03 hoyo