Class: EmulatorRecorder
- Defined in:
- lib/capa/emulator_recorder.rb
Instance Method Summary collapse
- #can_record? ⇒ Boolean
- #cancel ⇒ Object
- #emulator_video_path ⇒ Object
-
#initialize(filename: '') ⇒ EmulatorRecorder
constructor
A new instance of EmulatorRecorder.
- #pull_video_from_emulator ⇒ Object
- #record ⇒ Object
Constructor Details
#initialize(filename: '') ⇒ EmulatorRecorder
6 7 8 9 |
# File 'lib/capa/emulator_recorder.rb', line 6 def initialize(filename: '') abort('Please provide a name for the video') if filename.blank? @filename = filename end |
Instance Method Details
#can_record? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/capa/emulator_recorder.rb', line 47 def can_record? return false if command?('adb') == false # Example response # # "List of devices attached\n # emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1\n # emulator-5556 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:2\n\n" # `adb devices -l`.split("\n").count == 2 end |
#cancel ⇒ Object
34 35 36 |
# File 'lib/capa/emulator_recorder.rb', line 34 def cancel `adb shell killall screenrecord` end |
#emulator_video_path ⇒ Object
43 44 45 |
# File 'lib/capa/emulator_recorder.rb', line 43 def emulator_video_path "/sdcard/#{@filename}" end |
#pull_video_from_emulator ⇒ Object
38 39 40 41 |
# File 'lib/capa/emulator_recorder.rb', line 38 def pull_video_from_emulator # We can specify the device, in case there is more than one connected: -s emulator-5554 puts `adb pull #{emulator_video_path}` end |
#record ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/capa/emulator_recorder.rb', line 11 def record abort("You need exactly one emulator or device connected") unless can_record? Signal.trap("SIGINT") { raise Capa::UserAbort } Signal.trap("SIGTSTP") { raise Capa::UserAbort } Thread.new do # Might want to add '--size 720x1280' flag. That's the maximum permitted size for video recordings # We can specify the device, in case there is more than one connected: -s emulator-5554 = `adb shell screenrecord --verbose #{emulator_video_path}` abort("Maximum permitted resolution is 720x1280. Minimum Android version is Marshmallow.\n"\ "Please choose a different device.\n"\ "Tip: Galaxy Nexus works great!") if /err=-38/ =~ end puts 'Capturing video from the Android Emulator... Press ENTER to save' p = gets.chomp `adb shell killall -SIGINT screenrecord` sleep 0.5 pull_video_from_emulator end |