Merge pull request #56 from Nitwel/music-player

Finish media player implementation
This commit is contained in:
Nitwel 2023-11-29 00:47:58 +01:00 committed by GitHub
commit 300937f0fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 5 deletions

View File

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://content/entities/light/light.gd" id="1_ykxy3"] [ext_resource type="Script" path="res://content/entities/light/light.gd" id="1_ykxy3"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="4_4sfxb"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="4_4sfxb"]
[ext_resource type="Material" uid="uid://vce66e7sbc3n" path="res://content/entities/light/light_on.tres" id="5_50gph"] [ext_resource type="Material" uid="uid://vce66e7sbc3n" path="res://content/entities/light/light_on.tres" id="5_50gph"]
[ext_resource type="PackedScene" uid="uid://pk5k1q8bx0rj" path="res://content/ui/components/slider/slider.tscn" id="6_mhjlm"] [ext_resource type="PackedScene" path="res://content/ui/components/slider/slider.tscn" id="6_mhjlm"]
[sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"] [sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"]
radius = 0.05 radius = 0.05

View File

@ -10,8 +10,11 @@ extends StaticBody3D
@onready var title = $PlayingInfo/Title @onready var title = $PlayingInfo/Title
@onready var artist = $PlayingInfo/Artist @onready var artist = $PlayingInfo/Artist
@onready var http_request = $PlayingInfo/HTTPRequest @onready var http_request = $PlayingInfo/HTTPRequest
@onready var slider = $Slider
var playing = false var playing = false
var volume = 50
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -37,18 +40,25 @@ func _ready():
HomeApi.set_state(entity_id, "next") HomeApi.set_state(entity_id, "next")
) )
slider.on_value_changed.connect(set_volume)
func set_volume(value):
volume = value
HomeApi.set_state(entity_id, "volume", {"volume_level": value / 100})
func set_state(stateInfo): func set_state(stateInfo):
var state = stateInfo["state"] var state = stateInfo["state"]
print("State changed to ", stateInfo)
if state == "playing": if state == "playing":
if stateInfo["attributes"].has("entity_picture_local"): if stateInfo["attributes"].has("entity_picture_local"):
load_image(stateInfo["attributes"]["entity_picture_local"]) load_image(stateInfo["attributes"]["entity_picture_local"])
title.text = stateInfo["attributes"]["media_title"] title.text = stateInfo["attributes"]["media_title"]
artist.text = stateInfo["attributes"]["media_artist"] artist.text = stateInfo["attributes"]["media_artist"]
volume = float(stateInfo["attributes"]["volume_level"]) * 100
slider.value = volume
playing = true playing = true
play.label = "pause" play.label = "pause"
else: else:

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=5 format=3 uid="uid://dyktdg7ggiwl4"] [gd_scene load_steps=7 format=3 uid="uid://dyktdg7ggiwl4"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_8opk3"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_8opk3"]
[ext_resource type="Script" path="res://content/entities/media_player/media_player.gd" id="1_ame17"] [ext_resource type="Script" path="res://content/entities/media_player/media_player.gd" id="1_ame17"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="3_bguto"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="3_bguto"]
[ext_resource type="PackedScene" path="res://content/ui/components/slider/slider.tscn" id="4_w73hw"]
[ext_resource type="FontVariation" uid="uid://sshfnckriqxn" path="res://assets/icons/icons.tres" id="5_koe28"]
[sub_resource type="BoxShape3D" id="BoxShape3D_vi3eg"] [sub_resource type="BoxShape3D" id="BoxShape3D_vi3eg"]
size = Vector3(0.23, 0.142768, 0.01) size = Vector3(0.23, 0.142768, 0.01)
@ -56,3 +58,20 @@ pixel_size = 0.001
[node name="Movable" type="Node" parent="."] [node name="Movable" type="Node" parent="."]
script = ExtResource("3_bguto") script = ExtResource("3_bguto")
[node name="Slider" parent="." instance=ExtResource("4_w73hw")]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, -0.0562844, 0)
max = 100.0
value = 30.0
step = 1.0
show_label = true
label_unit = "%"
size = Vector3(15, 0.4, 1)
[node name="Label3D" type="Label3D" parent="Slider"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, -0.088399, 0, 0)
pixel_size = 0.001
text = "volume_up"
font = ExtResource("5_koe28")
font_size = 18
outline_size = 4

View File

@ -58,7 +58,7 @@ horizontal_alignment = 0
[node name="InputURL" parent="Content" instance=ExtResource("4_q3x6k")] [node name="InputURL" parent="Content" instance=ExtResource("4_q3x6k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, 0, 0.03) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.18, 0, 0.03)
text = "ws://192.168.33.33:8123" text = "ws://192.168.0.1:8123"
[node name="LabelToken" type="Label3D" parent="Content"] [node name="LabelToken" type="Label3D" parent="Content"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.01, 0, 0.07) transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.01, 0, 0.07)

View File

@ -254,6 +254,8 @@ func set_state(entity: String, state: String, attributes: Dictionary = {}):
service = "media_next_track" service = "media_next_track"
elif state == "previous": elif state == "previous":
service = "media_previous_track" service = "media_previous_track"
elif state == "volume":
service = "volume_set"
if service == null: if service == null:
return null return null