Class: DroidAdbs::ScreenRecord::Recording

Inherits:
Object
  • Object
show all
Defined in:
lib/droid_adbs/commons/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device_serial: nil, bit_rate: 3000000, size: "1280x720", time_limit: 180) ⇒ Recording

Returns a new instance of Recording.



12
13
14
15
16
17
18
19
# File 'lib/droid_adbs/commons/record.rb', line 12

def initialize(device_serial: nil, bit_rate: 3000000, size: "1280x720", time_limit: 180)
  @bit_rate = bit_rate
  @size = size
  @time_limit = time_limit

  ::DroidAdbs.device_serial = device_serial if device_serial
  @recording = false
end

Instance Attribute Details

#bit_rateObject

Returns the value of attribute bit_rate.



4
5
6
# File 'lib/droid_adbs/commons/record.rb', line 4

def bit_rate
  @bit_rate
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/droid_adbs/commons/record.rb', line 4

def size
  @size
end

Instance Method Details

#deleteObject



44
45
46
47
# File 'lib/droid_adbs/commons/record.rb', line 44

def delete
  # Delete the video from the device
  system "#{::DroidAdbs.shell} rm /sdcard/#{@file_name}.mp4"
end

#pull(export_to: "#{Dir.pwd}/droid_adbs_video.mp4") ⇒ Object



39
40
41
42
# File 'lib/droid_adbs/commons/record.rb', line 39

def pull(export_to: "#{Dir.pwd}/droid_adbs_video.mp4")
  # Download the video
  system "#{::DroidAdbs.adb_serial} pull /sdcard/#{@file_name}.mp4 #{export_to}"
end

#start(file_name: "droid_adbs_video") ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/droid_adbs/commons/record.rb', line 21

def start(file_name: "droid_adbs_video")
  validate_recordable?
  raise "Recording on the other process" if @recording

  @file_name = file_name

  @recording = true
  @process_id = fork do
    exec "#{::DroidAdbs.shell} screenrecord --time-limit #{@time_limit} --bit-rate #{@bit_rate} --size #{@size} /sdcard/#{@file_name}.mp4"
  end
end

#stopObject



33
34
35
36
37
# File 'lib/droid_adbs/commons/record.rb', line 33

def stop
  validate_recordable?
  Process.kill(:SIGINT, @process_id)
  @recording = false
end