<commit_before>var Playback = require('playback')
var Events = require('events')
var JST = require('../../base/jst')

var TICK_INTERVAL = 100

class ChromecastPlayback extends Playback {

  get name() { return 'chromecast_playback' }
  get template() { return JST.chromecast }

  constructor(options) {
    super(options)
    this.options = options
    this.src = options.src
    this.currentMedia = options.currentMedia
    this.mediaControl = options.mediaControl
    this.currentMedia.addUpdateListener(this.onMediaStatusUpdate.bind(this))
  }

  render() {
    var template = this.template()
    this.$el = $(template)
    this.$el.css({'background-image': 'url(' + this.options.poster + ')'})
  }

  play() {
    this.currentMedia.play()
  }

  pause() {
    this.currentMedia.pause()
    this.stopTimer()
  }

  stop() {
    this.currentMedia.stop()
    this.stopTimer()
  }

  startTimer() {
    this.timer = setInterval(() => this.updateMediaControl(), TICK_INTERVAL)
  }

  stopTimer() {
    clearInterval(this.timer)
    this.timer = null
  }

  isPlaying() {
    return this.currentMedia.playerState === 'PLAYING'
  }

  onMediaStatusUpdate() {
    this.mediaControl.changeTogglePlay()
    if (this.isPlaying() && !this.timer) {
      this.startTimer()
    }
  }

  updateMediaControl() {
    var position = this.currentMedia.getEstimatedTime()
    var duration = this.currentMedia.media.duration
    this.trigger(Events.PLAYBACK_TIMEUPDATE, position, duration, this.name)
  }

  show() {
    this.$el.show()
  }

  hide() {
    this.$el.hide()
  }
}

module.exports = ChromecastPlayback
<commit_msg>chromecast playback: add seek support<commit_after>var Playback = require('playback')
var Events = require('events')
var JST = require('../../base/jst')

var TICK_INTERVAL = 100

class ChromecastPlayback extends Playback {

  get name() { return 'chromecast_playback' }
  get template() { return JST.chromecast }

  constructor(options) {
    super(options)
    this.options = options
    this.src = options.src
    this.currentMedia = options.currentMedia
    this.mediaControl = options.mediaControl
    this.currentMedia.addUpdateListener(this.onMediaStatusUpdate.bind(this))
  }

  render() {
    var template = this.template()
    this.$el = $(template)
    this.$el.css({'background-image': 'url(' + this.options.poster + ')'})
  }

  play() {
    this.currentMedia.play()
  }

  pause() {
    this.currentMedia.pause()
    this.stopTimer()
  }

  stop() {
    this.currentMedia.stop()
    this.stopTimer()
  }

  seek(time) {
    this.stopTimer()
    var request = new chrome.cast.media.SeekRequest()
    request.currentTime = time * this.currentMedia.media.duration / 100
    this.currentMedia.seek(request,
      () => this.startTimer(), () => console.log('seek failed'))
  }

  startTimer() {
    this.timer = setInterval(() => this.updateMediaControl(), TICK_INTERVAL)
  }

  stopTimer() {
    clearInterval(this.timer)
    this.timer = null
  }

  isPlaying() {
    return this.currentMedia.playerState === 'PLAYING'
  }

  onMediaStatusUpdate() {
    this.mediaControl.changeTogglePlay()
    if (this.isPlaying() && !this.timer) {
      this.startTimer()
    }
  }

  updateMediaControl() {
    var position = this.currentMedia.getEstimatedTime()
    var duration = this.currentMedia.media.duration
    this.trigger(Events.PLAYBACK_TIMEUPDATE, position, duration, this.name)
  }

  show() {
    this.$el.show()
  }

  hide() {
    this.$el.hide()
  }
}

module.exports = ChromecastPlayback

{'fraction_non_alphanumeric': 0.14200341491178145, 'fraction_numerical': 0.0025611838360842347, 'mean_word_length': 3.2709599027946537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7141470', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1124, 'n_words': 194}