<commit_before>{View} = require 'atom'
vlc = require './vlc'
remote = require 'remote'
dialog = remote.require 'dialog'
mime = require 'mime'

isCodecSupported = (codec) ->
  # codec support: http://www.chromium.org/audio-video
  supportedCodecs = [
    'audio/ogg', 'application/ogg', 'video/ogg',
    'video/webm', 'audio/webm',
    'audio/wav', 'audio/x-wav'
  ]
  codecSupported = supportedCodecs.find (c) -> codec == c
  codecSupported != undefined

module.exports =
class VideoPlayerView extends View
  @content: ->
    @div class: 'video-player', =>
      @video autoplay: true

  initialize: (serializeState) ->
    atom.workspaceView.command "video-player:play", => @play()
    atom.workspaceView.command "video-player:stop", => @stop()
    atom.workspaceView.command "video-player:toggle-back-forth", => @toggleBackForth()
    atom.workspaceView.command "video-player:toggle-control", => @toggleControl()

  # Returns an object that can be retrieved when package is activated
  serialize: ->

  # Tear down any state and detach
  destroy: ->
    vlc.kill()
    @detach()

  stop: ->
    vlc.kill()
    @detach()

  play: ->
    self = this
    properties = ['openFile', 'multiSelections']
    dialog.showOpenDialog title: 'Open', properties: properties, (files) ->
      if files != undefined
        self._play files

  _play: (files) ->
    self = this

    vlc.kill()

    atom.workspaceView.find('.pane.active .item-views').append this
    video = atom.workspaceView.find '.video-player video'

    codecUnsupported = files.find (file) ->
      mimeType = mime.lookup file
      !isCodecSupported mimeType
    if codecUnsupported
      # when play unsupported file, try to use VLC
      streamServer = 'http://localhost:' + vlc.port
      video.attr 'src', streamServer
      vlc.streaming files, (data) ->
        # XXX set src when VLC start streaming
        self.reloadSrc()
      video.on 'ended', () ->
        self.reloadSrc()
    else
      video.attr 'src', files[0]

  reloadSrc: ->
    video = atom.workspaceView.find '.video-player video'
    src = video.attr 'src'
    video.attr 'src', src

  toggleBackForth: ->
    jQuery(this).toggleClass 'front'

  toggleControl: ->
    video = jQuery(this).find 'video'
    controls = video.attr 'controls'
    video.attr 'controls', !controls<commit_msg>multiple video files (close #1)<commit_after>{View} = require 'atom'
vlc = require './vlc'
remote = require 'remote'
dialog = remote.require 'dialog'
mime = require 'mime'

isCodecSupported = (codec) ->
  # codec support: http://www.chromium.org/audio-video
  supportedCodecs = [
    'audio/ogg', 'application/ogg', 'video/ogg',
    'video/webm', 'audio/webm',
    'audio/wav', 'audio/x-wav'
  ]
  codecSupported = supportedCodecs.find (c) -> codec == c
  codecSupported != undefined

module.exports =
class VideoPlayerView extends View
  @content: ->
    @div class: 'video-player', =>
      @video autoplay: true

  initialize: (serializeState) ->
    atom.workspaceView.command "video-player:play", => @play()
    atom.workspaceView.command "video-player:stop", => @stop()
    atom.workspaceView.command "video-player:toggle-back-forth", => @toggleBackForth()
    atom.workspaceView.command "video-player:toggle-control", => @toggleControl()

  # Returns an object that can be retrieved when package is activated
  serialize: ->

  # Tear down any state and detach
  destroy: ->
    vlc.kill()
    @detach()

  stop: ->
    vlc.kill()
    @detach()

  play: ->
    self = this
    properties = ['openFile', 'multiSelections']
    dialog.showOpenDialog title: 'Open', properties: properties, (files) ->
      if files != undefined
        self._play files

  _play: (files) ->
    self = this

    vlc.kill()

    atom.workspaceView.find('.pane.active .item-views').append this
    video = atom.workspaceView.find '.video-player video'

    codecUnsupported = files.find (file) ->
      mimeType = mime.lookup file
      !isCodecSupported mimeType
    if codecUnsupported
      # when play unsupported file, try to use VLC
      streamServer = 'http://localhost:' + vlc.port
      video.attr 'src', streamServer
      vlc.streaming files, (data) ->
        # XXX set src when VLC start streaming
        self.reloadSrc()
      video.on 'ended', () ->
        self.reloadSrc()
    else
      counter = 0
      video.attr 'src', files[counter]
      video.on 'ended', () ->
        ++counter
        if (counter < files.length)
          video.attr 'src', files[counter]

  reloadSrc: ->
    video = atom.workspaceView.find '.video-player video'
    src = video.attr 'src'
    video.attr 'src', src

  toggleBackForth: ->
    jQuery(this).toggleClass 'front'

  toggleControl: ->
    video = jQuery(this).find 'video'
    controls = video.attr 'controls'
    video.attr 'controls', !controls
{'fraction_non_alphanumeric': 0.13837523374194888, 'fraction_numerical': 0.0006233118637024725, 'mean_word_length': 2.9654036243822075, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5297111', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1477, 'n_words': 374}