Class: AirPlayer::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/airplayer/controller.rb

Constant Summary collapse

BufferingTimeoutError =
Class.new(TimeoutError)

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/airplayer/controller.rb', line 9

def initialize
  @airplay      = Airplay::Client.new
  @device       = @airplay.browse.first
  @player       = nil
  @progressbar  = nil
  @timeout      = 30
  @interval     = 1
  @total_sec    = 0
  @current_sec  = 0
rescue Airplay::Client::ServerNotFoundError
  abort '[ERROR] Apple device not found'
end

Instance Method Details

#pauseObject



40
41
42
43
# File 'lib/airplayer/controller.rb', line 40

def pause
  @player.stop        if @player
  @progressbar.finish if @progressbar
end

#play(media) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/airplayer/controller.rb', line 22

def play(media)
  raise TypeError unless media.kind_of? Media

  display_information(media)
  @player = @airplay.send_video(media.open)

  buffering
  @progressbar.progress = @current_sec while playing

  @progressbar.title = :Complete
  pause
  media.close
rescue BufferingTimeoutError
  abort '[ERROR] Buffering timeout'
rescue TypeError
  abort '[ERROR] Not media class'
end

#replayObject



45
46
47
48
49
50
51
# File 'lib/airplayer/controller.rb', line 45

def replay
  @player.scrub(0)
  @player.resume

  @progressbar.reset
  @progressbar.resume
end