Updated how players and song list works

Made many changes with caching, how players works, added sound effects
and animations any many more things
This commit is contained in:
2024-12-27 20:35:28 +01:00
parent c4a7d743d3
commit 23f2ed11eb
18 changed files with 612 additions and 359 deletions

View File

@@ -13,6 +13,12 @@ var restart_button: TextureButton = $MusicPlayerContainer/RestartTextureButton
@onready
var audio_player: AudioStreamPlayer = $AudioStreamPlayer
@onready
var sound_player: AudioStreamPlayer = $AudioSoundPlayer
@onready
var sound_effect_player: AudioStreamPlayer = $AudioSoundEffectPlayer
@onready
var progress_slider: HSlider = $MusicPlayerContainer/MusicPlayerSlider
@@ -35,10 +41,8 @@ var playback_position: float
var stream: AudioStream
var song_finished: bool = false
signal fetched
signal winner(player_name: String)
signal add_to_queue
signal show_answer
signal update_song_list
signal play_next_song
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -98,7 +102,7 @@ func _on_finished() -> void:
play_button.texture_normal = play_icon
song_finished = true
if !Settings.stop_after_current:
fetch_next_song()
play_next_song.emit()
if Settings.auto_repeat_song:
restart()
@@ -133,59 +137,53 @@ func _on_point_triggered(point: String) -> void:
elif point == "match":
play_sound(preload("res://sounds/sound0.mp3"))
func play_sound_effect(sound_effect_name: AudioStream) -> void:
sound_effect_player.stream = sound_effect_name
sound_effect_player.play()
func play_sound(sound_name: AudioStream) -> void:
audio_player.stream = sound_name
audio_player.play()
song_finished = false
play_button.texture_normal = pause_icon
stream = audio_player.stream
progress_slider.max_value = round(stream.get_length())
progress_slider.tick_count = round(stream.get_length() / 60)
sound_player.stream = sound_name
audio_player.stop()
sound_player.play()
song_finished = true
play_button.texture_normal = play_icon
progress_slider.value = 0
if stream != null:
music_time_label.text = format_text(progress_slider.value, stream.get_length())
func play_song(body: PackedByteArray) -> void:
var sound: AudioStream = AudioStreamMP3.new()
sound.data = body
audio_player.stream = sound
audio_player.play()
sound_player.stop()
song_finished = false
play_button.texture_normal = pause_icon
stream = audio_player.stream
progress_slider.max_value = round(stream.get_length())
progress_slider.tick_count = round(stream.get_length() / 60)
progress_slider.tick_count = round(stream.get_length() / 60)
func song_fetched(body: PackedByteArray) -> void:
func play_song_object(song_object_no: int) -> void:
print("play_song_object")
if audio_player.is_playing():
audio_player.stop()
await get_tree().create_timer(1.0).timeout
print("song_fetched")
var sound: AudioStream = AudioStreamMP3.new()
sound.data = body
print("play given song")
audio_player.stream = sound
await get_tree().create_timer(0.5).timeout
audio_player.stream = Settings.song_object_array[song_object_no].song
sound_player.stop()
audio_player.play()
song_finished = false
play_button.texture_normal = pause_icon
stream = audio_player.stream
progress_slider.max_value = round(stream.get_length())
progress_slider.tick_count = round(stream.get_length() / 60)
add_to_queue.emit()
if Settings.add_to_stats:
print("add to stats")
Settings.make_request3("/music/addPlayed")
Settings.currently_playing_song = song_object_no
Settings.unset_is_playing()
if !Settings.hide_next_track:
show_answer.emit()
func fetch_next_song() -> void:
#if audio_player.is_playing():
# audio_player.stop()
# await get_tree().create_timer(1.0).timeout
print("fetch_next_song")
var url: String = ""
if Settings.use_low_played_mode:
url = "/music/rand/low"
else:
url = "/music/rand"
Settings.make_request2(url, song_fetched, true)
print("Show answer now!!")
Settings.song_object_array[song_object_no].is_answered = true
Settings.song_object_array[song_object_no].has_played = true
Settings.song_object_array[song_object_no].is_playing = true
update_song_list.emit()
func get_sound_test_song() -> void:
Settings.make_request2("/music/soundTest", play_song, true)