Changer.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. extends Control
  2. @onready var item_list = get_node(^"ItemList")
  3. func _ready():
  4. for item in AudioServer.get_output_device_list():
  5. item_list.add_item(item)
  6. var device = AudioServer.get_output_device()
  7. for i in range(item_list.get_item_count()):
  8. if device == item_list.get_item_text(i):
  9. item_list.select(i)
  10. break
  11. func _process(_delta):
  12. var speaker_mode_text = "Stereo"
  13. var speaker_mode = AudioServer.get_speaker_mode()
  14. if speaker_mode == AudioServer.SPEAKER_SURROUND_31:
  15. speaker_mode_text = "Surround 3.1"
  16. elif speaker_mode == AudioServer.SPEAKER_SURROUND_51:
  17. speaker_mode_text = "Surround 5.1"
  18. elif speaker_mode == AudioServer.SPEAKER_SURROUND_71:
  19. speaker_mode_text = "Surround 7.1"
  20. $DeviceInfo.text = "Current Device: " + AudioServer.get_output_device() + "\n"
  21. $DeviceInfo.text += "Speaker Mode: " + speaker_mode_text
  22. func _on_Button_button_down():
  23. for item in item_list.get_selected_items():
  24. var device = item_list.get_item_text(item)
  25. AudioServer.set_output_device(device)
  26. func _on_Play_Audio_button_down():
  27. if $AudioStreamPlayer.playing:
  28. $AudioStreamPlayer.stop()
  29. $PlayAudio.text = "Play Audio"
  30. else:
  31. $AudioStreamPlayer.play()
  32. $PlayAudio.text = "Stop Audio"