Class: DeviceAPI::Android::Plugin::Audio
- Inherits:
-
Object
- Object
- DeviceAPI::Android::Plugin::Audio
- Defined in:
- lib/device_api/android/plugins/audio.rb
Instance Attribute Summary collapse
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
Instance Method Summary collapse
- #get_current_volume ⇒ Object
- #get_volume_steps ⇒ Object
-
#initialize(options) ⇒ Audio
constructor
A new instance of Audio.
- #is_muted? ⇒ Boolean
- #max_volume ⇒ Object
- #min_volume ⇒ Object
- #volume ⇒ Object
Constructor Details
#initialize(options) ⇒ Audio
Returns a new instance of Audio.
8 9 10 |
# File 'lib/device_api/android/plugins/audio.rb', line 8 def initialize() @qualifier = #[:serial] end |
Instance Attribute Details
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
6 7 8 |
# File 'lib/device_api/android/plugins/audio.rb', line 6 def qualifier @qualifier end |
Instance Method Details
#get_current_volume ⇒ Object
20 21 22 23 24 25 |
# File 'lib/device_api/android/plugins/audio.rb', line 20 def get_current_volume system = get_system_volume volume = system.select { |a| a.include?('Current') }.first volume.scan(/Current: 2:\s(.*?),(:?.*)/).flatten.first.to_i end |
#get_volume_steps ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/device_api/android/plugins/audio.rb', line 12 def get_volume_steps audio = ADB.dumpsys( @qualifier, 'audio' ) vol_steps = audio.detect { |a| a.include?('volume steps:') } return nil if vol_steps.nil? vol_steps.scan(/volume steps: (.*)/).flatten.first.to_i end |
#is_muted? ⇒ Boolean
27 28 29 30 31 |
# File 'lib/device_api/android/plugins/audio.rb', line 27 def is_muted? system = get_system_volume mute = system.select { |a| a.include?('Mute') }.first mute.scan(/Mute count: (.*)/).flatten.first.to_i > 0 end |
#max_volume ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/device_api/android/plugins/audio.rb', line 40 def max_volume vol = get_current_volume steps = get_volume_steps change_volume(steps - vol, 24) get_current_volume == steps end |
#min_volume ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/device_api/android/plugins/audio.rb', line 49 def min_volume vol = get_current_volume change_volume(vol, 25) get_current_volume == 0 # adb shell service call audio 4 i32 1 i32 0 i32 1 end |
#volume ⇒ Object
33 34 35 36 37 38 |
# File 'lib/device_api/android/plugins/audio.rb', line 33 def volume return 0 if is_muted? steps = get_volume_steps vol = get_current_volume ((vol.to_f / steps.to_f) * 100).to_i end |