Fixed light icons. Made the search "better". Added more shortcuts and tried to fix som bugs.
This commit is contained in:
@@ -16,20 +16,24 @@ var audio_player: AudioStreamPlayer = $AudioStreamPlayer
|
||||
@onready
|
||||
var progress_slider: HSlider = $MusicPlayerContainer/MusicPlayerSlider
|
||||
|
||||
@onready
|
||||
var volume_slider: HSlider = $MusicPlayerContainer/VolumeSlider
|
||||
|
||||
@onready
|
||||
var music_time_label: Label = $MusicPlayerContainer/MusicTimeLabel
|
||||
|
||||
@onready
|
||||
var path: String = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns of the Patriots/2-16 Metal Gear Saga.mp3'
|
||||
|
||||
var play_icon: Texture = preload("res://icons/play_icon.svg")
|
||||
var pause_icon: Texture = preload("res://icons/pause_icon.svg")
|
||||
var play_icon: Texture = preload("res://icons/play_icon_light.svg")
|
||||
var pause_icon: Texture = preload("res://icons/pause_icon_light.svg")
|
||||
|
||||
var songs: Array = []
|
||||
|
||||
var is_changing: bool = false
|
||||
var playback_position: float
|
||||
var stream: AudioStream
|
||||
var song_finished: bool = false
|
||||
|
||||
signal fetched
|
||||
signal winner(player_name: String)
|
||||
@@ -42,6 +46,8 @@ func _ready() -> void:
|
||||
restart_button.pressed.connect(restart)
|
||||
progress_slider.drag_started.connect(_on_drag_started)
|
||||
progress_slider.drag_ended.connect(_on_drag_ended)
|
||||
|
||||
audio_player.finished.connect(_on_finished)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if audio_player.has_stream_playback() && !is_changing && !audio_player.stream_paused:
|
||||
@@ -55,14 +61,17 @@ func format_time(time: float) -> String:
|
||||
var mins: String = "%02d" % floor(time / 60)
|
||||
var sec: String = "%02d" % round(fmod(time, 60))
|
||||
return mins + ":" + sec
|
||||
|
||||
|
||||
func format_text(part: float, total: float) -> String:
|
||||
return format_time(part) + " / " + format_time(total)
|
||||
|
||||
func play_or_pause() -> void:
|
||||
if audio_player.stream_paused:
|
||||
if song_finished:
|
||||
restart()
|
||||
elif audio_player.stream_paused:
|
||||
play_button.texture_normal = pause_icon
|
||||
audio_player.stream_paused = false
|
||||
song_finished = false
|
||||
audio_player.seek(playback_position)
|
||||
print("continue")
|
||||
progress_slider.max_value = round(stream.get_length())
|
||||
@@ -75,12 +84,17 @@ func play_or_pause() -> void:
|
||||
func restart() -> void:
|
||||
audio_player.stop()
|
||||
audio_player.stream_paused = false
|
||||
song_finished = false
|
||||
progress_slider.value = 0
|
||||
playback_position = audio_player.get_playback_position()
|
||||
audio_player.seek(playback_position)
|
||||
play_button.texture_normal = pause_icon
|
||||
audio_player.play()
|
||||
|
||||
func _on_finished() -> void:
|
||||
play_button.texture_normal = play_icon
|
||||
song_finished = true
|
||||
|
||||
func _on_drag_started() -> void:
|
||||
is_changing = true
|
||||
|
||||
@@ -88,7 +102,18 @@ func _on_drag_ended(_changed: bool) -> void:
|
||||
audio_player.seek(progress_slider.value)
|
||||
playback_position = progress_slider.value
|
||||
is_changing = false
|
||||
|
||||
func seek(position: float) -> void:
|
||||
progress_slider.value += position
|
||||
is_changing = true
|
||||
audio_player.seek(progress_slider.value)
|
||||
playback_position = progress_slider.value
|
||||
is_changing = false
|
||||
|
||||
func change_volume(value: float) -> void:
|
||||
volume_slider.value += value
|
||||
volume_slider.change_volume(volume_slider.value)
|
||||
|
||||
func _on_point_triggered(point: String) -> void:
|
||||
if point == "first":
|
||||
var value: int = randi_range(0, 10)
|
||||
@@ -104,6 +129,7 @@ func _on_point_triggered(point: String) -> void:
|
||||
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())
|
||||
@@ -114,32 +140,43 @@ func play_song(body: PackedByteArray) -> void:
|
||||
sound.data = body
|
||||
audio_player.stream = sound
|
||||
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)
|
||||
|
||||
func song_fetched(body: PackedByteArray) -> void:
|
||||
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
|
||||
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:
|
||||
Settings.make_request3("/music/played")
|
||||
print("add to stats")
|
||||
Settings.make_request3("/music/addPlayed")
|
||||
if !Settings.stop_after_current:
|
||||
audio_player.finished.connect(fetch_next_song)
|
||||
if !Settings.hide_next_track:
|
||||
show_answer.emit()
|
||||
|
||||
add_to_queue.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"
|
||||
|
||||
Reference in New Issue
Block a user