<commit_before>/**
 * Module dependencies
 */

var EventEmitter = require('events');
var loadAPI = require('./lib/load-api');
var prepareEmbed = require('./lib/prepare-embed');

/**
 * Expose `SoundCloud`
 */

module.exports = SoundCloud;

/**
 * Create new `SoundCloud` player
 *
 * @param {String} id of embedded widget
 */

function SoundCloud(id) {
  sdk = loadAPI();
  prepareEmbed(id);
  this.createPlayer(id);
}

/**
 * Mixin events
 */

SoundCloud.prototype = new EventEmitter();

/**
 * Create a controller for the widget
 *
 * @param {String} id of embedded widget
 * @api private
 */

SoundCloud.prototype.createPlayer = function(id) {
  var self = this;
  sdk(function(err, SC) {
    self.player = new SC.Widget(id);
    self.bindEvents();
  });
};

/**
 * Play the track.
 *
 * @api public
 */

SoundCloud.prototype.play = function() {
  this.player.play();
};

/**
 * Pause the track.
 *
 * @api public
 */

SoundCloud.prototype.pause = function() {
  this.player.pause();
};

/**
 * Bind events to player
 *
 * @api private
 */

SoundCloud.prototype.bindEvents = function() {
  var self = this;
  
  self.player.bind(SC.Widget.Events.READY, function() {
    self.emit('ready');
  });

  self.player.bind(SC.Widget.Events.PLAY, function() {
    self.emit('play');
  });

  self.player.bind(SC.Widget.Events.PAUSE, function() {
    self.emit('pause');
  });

  self.player.bind(SC.Widget.Events.FINISH, function() {
    self.emit('end');
  });
};<commit_msg>use explicit `window.SC`<commit_after>/**
 * Module dependencies
 */

var EventEmitter = require('events');
var loadAPI = require('./lib/load-api');
var prepareEmbed = require('./lib/prepare-embed');

/**
 * Expose `SoundCloud`
 */

module.exports = SoundCloud;

/**
 * Create new `SoundCloud` player
 *
 * @param {String} id of embedded widget
 */

function SoundCloud(id) {
  sdk = loadAPI();
  prepareEmbed(id);
  this.createPlayer(id);
}

/**
 * Mixin events
 */

SoundCloud.prototype = new EventEmitter();

/**
 * Create a controller for the widget
 *
 * @param {String} id of embedded widget
 * @api private
 */

SoundCloud.prototype.createPlayer = function(id) {
  var self = this;
  sdk(function(err, SC) {
    self.player = new window.SC.Widget(id);
    self.bindEvents();
  });
};

/**
 * Play the track.
 *
 * @api public
 */

SoundCloud.prototype.play = function() {
  this.player.play();
};

/**
 * Pause the track.
 *
 * @api public
 */

SoundCloud.prototype.pause = function() {
  this.player.pause();
};

/**
 * Bind events to player
 *
 * @api private
 */

SoundCloud.prototype.bindEvents = function() {
  var self = this;
  
  self.player.bind(window.SC.Widget.Events.READY, function() {
    self.emit('ready');
  });

  self.player.bind(window.SC.Widget.Events.PLAY, function() {
    self.emit('play');
  });

  self.player.bind(window.SC.Widget.Events.PAUSE, function() {
    self.emit('pause');
  });

  self.player.bind(window.SC.Widget.Events.FINISH, function() {
    self.emit('end');
  });
};
{'fraction_non_alphanumeric': 0.1813922356091031, 'fraction_numerical': 0.0, 'mean_word_length': 3.3256150506512303, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5535839', 'n_tokens_mistral': 1013, 'n_tokens_neox': 1002, 'n_words': 204}