Skip to content

Instantly share code, notes, and snippets.

@evanxd
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanxd/41d8e2d91c5201a42bfa to your computer and use it in GitHub Desktop.
Save evanxd/41d8e2d91c5201a42bfa to your computer and use it in GitHub Desktop.
Proposal of Audio Channel Management API

Proposal of mozBrowser1 APIs for Audio Channel Management

Properties

  • mozBrowser.audioChannel.playingChannels: A list of playing audio channels.

Methods

  • mozBrowser.audioChannel.allow(): Allow to play for some specific channels.
  • mozBrowser.audioChannel.deny(): Deny to play for some specific channels.

mozBrowser.audioChannel.allow()

Parameters

  • channels: Audio channels we want to play.

mozBrowser.audioChannel.deny()

Parameters

  • channels: Audio channels we don't want to play.

Events

  • mozaudiochannelchange: Sent when audio channel changes.

mozaudiochannelchange

Properties

Detail
  • channel: A new audio channel app would like to play.

Examples

Allow a channel

app.element.addEventListener('mozaudiochannelchange', function(evt) {
  var channel = evt.detail.channel;
  app.element.audioChannel.allow(channel);
});

Handle audio channel competing

dialerApp.element.addEventListener('mozaudiochannelchange', function(evt) {
  var channel = evt.detail.channel;
  // audioChannelManager is what we want to have in Gaia to manage audio channels.
  if (audioChannelManager.isAllowed(channel)) {
    audioChannelManager.playingApps.forEach(function(ele) {
      ele.audioChannel.deny()
    });
    dialerApp.element.audioChannel.allow();
  }
});
@evanxd
Copy link
Author

evanxd commented Nov 27, 2014

Still has no idea to handle the loop issue, even we have the above APIs.

@evanxd
Copy link
Author

evanxd commented Dec 5, 2014

mozBrowser.allowedAudioChannels.add('content') => mozBrowser.channels.content = 1

@evanxd
Copy link
Author

evanxd commented Dec 5, 2014

=>

mozBrowser.allowedAudioChannels[audioChannel]
AudioChannel {
  active,
  volume,
  muted
}

mozBrowser.allowedAudioChannels['content'].muted = true; // allow the playing
mozBrowser.allowedAudioChannels['content'].muted = false; // pause the playing

@evanxd
Copy link
Author

evanxd commented Dec 15, 2014

mozBrowser.enable(ch)
mozBrowser.disable(ch)
mozBrowser.getChannelState(ch): enable, disable
mozBrowser.changeVolume(ch, vol)

mozaudiochannelchanged: state, ch, video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment