audio loading
This commit is contained in:
@@ -24,7 +24,7 @@ bus/1/name = &"Music"
|
||||
bus/1/solo = false
|
||||
bus/1/mute = false
|
||||
bus/1/bypass_fx = false
|
||||
bus/1/volume_db = 0.0
|
||||
bus/1/volume_db = -10.986328
|
||||
bus/1/send = &"Master"
|
||||
bus/1/effect/0/effect = SubResource("AudioEffectReverb_tqf74")
|
||||
bus/1/effect/0/enabled = false
|
||||
|
||||
+29
-1
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://mfcbf2sfino6"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://mfcbf2sfino6"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://0jo87vtoeheu" path="res://Images/pole2.jpg" id="1_6bp64"]
|
||||
[ext_resource type="Texture2D" uid="uid://df2e70jxwrmjs" path="res://Icons/BackOne.png" id="1_8gbba"]
|
||||
@@ -42,6 +42,15 @@ func update(on:bool):
|
||||
showbutton.visible = on != true
|
||||
"
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_d1ilt"]
|
||||
resource_name = "Slider"
|
||||
script/source = "extends VSlider
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
AudioServer.set_bus_volume_db(AudioServer.get_bus_index(\"Music\"),linear_to_db(value))
|
||||
|
||||
"
|
||||
|
||||
[node name="Main" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
@@ -232,6 +241,25 @@ layout_mode = 2
|
||||
icon = ExtResource("4_kry3j")
|
||||
expand_icon = true
|
||||
|
||||
[node name="VolumeSlider" type="VSlider" parent="Padding/VBoxContainer/Bottom/HBoxContainer/Volume"]
|
||||
custom_minimum_size = Vector2(0, 100)
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -9.0
|
||||
offset_top = -50.0
|
||||
offset_right = 7.0
|
||||
offset_bottom = -42.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
max_value = 1.0
|
||||
step = 0.010000000009313226
|
||||
value = 1.0
|
||||
script = SubResource("GDScript_d1ilt")
|
||||
|
||||
[node name="FileDialog" type="FileDialog" parent="."]
|
||||
oversampling_override = 1.0
|
||||
title = "Open a Directory"
|
||||
|
||||
@@ -12,15 +12,17 @@ font_color = Color(0.7919991, 0.79199916, 0.7919991, 1)
|
||||
shadow_size = 2
|
||||
shadow_color = Color(0, 0, 0, 0.5647059)
|
||||
|
||||
[node name="SongDisplay" type="Control" node_paths=PackedStringArray("background", "NameLabel", "ArtistLabel")]
|
||||
[node name="SongDisplay" type="Control" node_paths=PackedStringArray("background", "NameLabel", "ArtistLabel", "PlayButton")]
|
||||
custom_minimum_size = Vector2(0, 75)
|
||||
layout_mode = 3
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
script = ExtResource("1_76jf4")
|
||||
background = NodePath("TextureRect")
|
||||
NameLabel = NodePath("VBoxContainer/Name")
|
||||
ArtistLabel = NodePath("VBoxContainer/Artist")
|
||||
PlayButton = NodePath("Playbutton")
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
layout_mode = 1
|
||||
|
||||
@@ -35,6 +35,33 @@ public partial class Context : Node
|
||||
SongsUpdated.Invoke(this,e);
|
||||
}
|
||||
|
||||
AudioStreamPlayer Player;
|
||||
public void PlaySong(){
|
||||
GD.Print("PlaySongFromDisk");
|
||||
Player?.Play();
|
||||
}
|
||||
public void LoadSong(String Path){
|
||||
Player?.QueueFree();
|
||||
if (Path.ToLower().EndsWith(".mp3")){
|
||||
AudioStreamMP3 stream = AudioStreamMP3.LoadFromFile(Path);
|
||||
Player = new AudioStreamPlayer();
|
||||
Player.Stream = stream;
|
||||
AddChild(Player);
|
||||
}
|
||||
else if(Path.ToLower().EndsWith(".wav")){
|
||||
AudioStreamWav stream = AudioStreamWav.LoadFromFile(Path);
|
||||
Player = new AudioStreamPlayer();
|
||||
Player.Stream = stream;
|
||||
AddChild(Player);
|
||||
}
|
||||
else if(Path.ToLower().EndsWith(".ogg")){
|
||||
AudioStreamOggVorbis stream = AudioStreamOggVorbis.LoadFromFile(Path);
|
||||
Player = new AudioStreamPlayer();
|
||||
Player.Stream = stream;
|
||||
AddChild(Player);
|
||||
}
|
||||
Player.Bus = "Music";
|
||||
}
|
||||
}
|
||||
|
||||
public class SongsUpdatedEventArgs : EventArgs
|
||||
|
||||
@@ -9,6 +9,7 @@ public partial class SongDisplay : Control
|
||||
[Export] TextureRect background;
|
||||
[Export] Label NameLabel;
|
||||
[Export] Label ArtistLabel;
|
||||
[Export] Button PlayButton;
|
||||
public void Setup(Song info){
|
||||
SavedInfo = info;
|
||||
Image image = info.LoadImage();
|
||||
@@ -21,5 +22,10 @@ public partial class SongDisplay : Control
|
||||
ArtistLabel.Text = SavedInfo.Artists[0];
|
||||
|
||||
}
|
||||
PlayButton.Pressed += ButtonPressed;
|
||||
}
|
||||
void ButtonPressed(){
|
||||
Context.instance.LoadSong(SavedInfo.Directory);
|
||||
Context.instance.PlaySong();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user