<commit_before>// Copyright 2014 Globo.com Player authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

var UIPlugin = require('../../base/ui_object'); //FIXME

var HTML5AudioPlaybackPlugin = UIPlugin.extend({
  events: {
    'timeupdate': 'timeUpdated',
    'ended': 'ended'
  },
  tagName: 'audio',
  initialize: function(options) {
    this.el.src = options.src;
    this.container.settings = {
      left: ['playpause'],
      right: ['volume'],
      default: ['seekbar']
    };
    this.listenTo(this.container, 'container:play', this.play);
    this.listenTo(this.container, 'container:pause', this.pause);
    this.listenTo(this.container, 'container:seek', this.seek);
    this.listenTo(this.container, 'container:volume', this.volume);
    this.listenTo(this.container, 'container:stop', this.stop);
    this.render(); // it should render when the container trigger 'ready'
    options.autoPlay && this.container.play();
  },
  play: function() {
    this.el.play();
  },
  pause: function() {
    this.el.pause();
  },
  stop: function() {
    this.pause();
    this.el.currentTime = 0;
  },
  volume: function(value) {
    this.el.volume = value / 100;
  },
  mute: function() {
    this.el.volume = 0;
  },
  unmute: function() {
    this.el.volume = 1;
  },
  isMuted: function() {
    return !!this.el.volume;
  },
  ended: function() {
    this.trigger('container:timeupdate', 0);
  },
  seek: function(seekBarValue) {
    var time = this.el.duration * (seekBarValue / 100);
    this.el.currentTime = time;
  },
  getCurrentTime: function() {
    return this.el.currentTime;
  },
  getDuration: function() {
    return this.el.duration;
  },
  timeUpdated: function() {
    var time = (100 / this.el.duration) * this.el.currentTime;
    this.container.timeUpdated(time);
  },
  render: function() {
    this.container.$el.append(this.el);
    return this;
  }
 });

HTML5AudioPlaybackPlugin.canPlay = function(resource) {
  return !!resource.match(/(.*).mp3/);
}


module.exports = HTML5AudioPlaybackPlugin;
<commit_msg>html5 audio plugin: update to use new plugin format<commit_after>// Copyright 2014 Globo.com Player authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

var UIPlugin = require('../../base/ui_plugin');

var HTML5AudioPlaybackPlugin = UIPlugin.extend({
  name: 'html5_audio_playback',
  type: 'playback',
  tagName: 'audio',
  events: {
    'timeupdate': 'timeUpdated',
    'ended': 'ended'
  },

  initialize: function(options) {
    this.super('initialize');
    this.el.src = options.src;
    this.container.settings = {
      left: ['playpause'],
      right: ['volume'],
      default: ['seekbar']
    };
    this.render(); // it should render when the container trigger 'ready'
    options.autoPlay && this.container.play();
  },

  bindEvents: function() {
    this.listenTo(this.container, 'container:play', this.play);
    this.listenTo(this.container, 'container:pause', this.pause);
    this.listenTo(this.container, 'container:seek', this.seek);
    this.listenTo(this.container, 'container:volume', this.volume);
    this.listenTo(this.container, 'container:stop', this.stop);
  },

  play: function() {
    this.el.play();
  },

  pause: function() {
    this.el.pause();
  },

  stop: function() {
    this.pause();
    this.el.currentTime = 0;
  },

  volume: function(value) {
    this.el.volume = value / 100;
  },

  mute: function() {
    this.el.volume = 0;
  },

  unmute: function() {
    this.el.volume = 1;
  },

  isMuted: function() {
    return !!this.el.volume;
  },

  ended: function() {
    this.trigger('container:timeupdate', 0);
  },

  seek: function(seekBarValue) {
    var time = this.el.duration * (seekBarValue / 100);
    this.el.currentTime = time;
  },

  getCurrentTime: function() {
    return this.el.currentTime;
  },

  getDuration: function() {
    return this.el.duration;
  },

  timeUpdated: function() {
    var time = (100 / this.el.duration) * this.el.currentTime;
    this.container.timeUpdated(time);
  },

  render: function() {
    this.container.$el.append(this.el);
    return this;
  }
 });

HTML5AudioPlaybackPlugin.canPlay = function(resource) {
  return !!resource.match(/(.*).mp3/);
}


module.exports = HTML5AudioPlaybackPlugin;

{'fraction_non_alphanumeric': 0.1613931254268154, 'fraction_numerical': 0.010015934441156385, 'mean_word_length': 3.2209414024975986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3311895', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1429, 'n_words': 308}