Sha256: ecf7d01853128e907a422ed513daae795c686c40057854ef574265deae48dc74

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module Playa
  class Player
    include Vedeu

    def initialize
      event(:forward) { forward if playing? }
      event(:rewind)  { rewind if playing? }
      event(:toggle)  { toggle }
      event(:play) do |track|
        stop if playing?

        open(track)

        play
      end
    end

    def play
      player.start_stream
    end

    def stop
      player.stop_stream
    end

    def rewind
      player.rewind(5)
    end

    def forward
      player.forward(5)
    end

    def toggle
      if playing?
        stop
      else
        play
      end
    end

    def playing?
      player.active || false
    end

    def counter
      player.position
    end

    def progress
      if playing?
        counter / @track.duration
      else
        0
      end
    end

    def level
      player.level
    end

    def events
      player.events
    end

    def track
      @track
    end

    private

    def open(track)
      @track = track

      player.load(track.filename)
    end

    def player
      @_player ||= Audite.new
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
playa-0.1.0 lib/playa/models/player.rb
playa-0.0.15 lib/playa/models/player.rb
playa-0.0.14 lib/playa/models/player.rb
playa-0.0.13 lib/playa/models/player.rb