-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVRControl.HeosUI.cs
More file actions
152 lines (132 loc) · 5.52 KB
/
Copy pathAVRControl.HeosUI.cs
File metadata and controls
152 lines (132 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright (C) 2026 SAMDestroy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
namespace AVRControl
{
public partial class AVRControl
{
private async Task LoadAlbumArtAsync(string url)
{
if (string.IsNullOrEmpty(url))
{
pbAlbumArt.Image = null; // or default image
return;
}
try
{
byte[] imageBytes = await _httpClient.GetByteArrayAsync(url);
using var ms = new System.IO.MemoryStream(imageBytes);
pbAlbumArt.Image = Image.FromStream(ms);
pbAlbumArt.SizeMode = PictureBoxSizeMode.Zoom;
}
catch (Exception ex)
{
Console.WriteLine("Fehler beim Laden des Covers: " + ex.Message);
}
}
private void ParseAndDisplayTrackInfo(string json)
{
try
{
string song = ExtractJsonValue(json, "song");
string artist = ExtractJsonValue(json, "artist");
string album = ExtractJsonValue(json, "album");
string sidStr = ExtractJsonValue(json, "sid");
string state = ExtractJsonValue(json, "state").Trim().ToLower();
string curPosStr = ExtractJsonValue(json, "cur_pos");
string durationStr = ExtractJsonValue(json, "duration");
int.TryParse(sidStr, out int sid);
if (!timerProgress.Enabled && state != "pause")
{
timerProgress.Start();
this.btnHeosPlayPause.BackgroundImage = global::AVRControl.Properties.Resources.PauseIcon;
}
string imageUrl = ExtractJsonValue(json, "image_url");
_ = LoadAlbumArtAsync(imageUrl);
// Spotify Fix
string serviceName = "HEOS";
if (sid == 4)
{
if (json.ToLower().Contains("spotify") || album.ToLower().Contains("spotify"))
serviceName = "Spotify Connect";
else
serviceName = "HEOS Music";
}
else
{
serviceName = sid switch
{
1 => "Pandora",
3 => "TuneIn Radio",
4 => "Napster / Media Server",
5 => "Deezer",
9 => "SoundCloud",
10 => "Spotify (App)",
13 => "Amazon Music",
18 => "TIDAL",
1024 => "Musikserver / DLNA",
1027 => "AUX Eingang",
_ => $"Dienst {sid}"
};
}
_lastHeosService = serviceName;
this.AVRSource.Text = _lastHeosService;
this.lblCurrentSource.Text = _lastHeosService;
this.HeosTrackInfoArtist.Text = artist;
this.HeosTrackInfoAlbum.Text = album;
this.HeosTrackInfoSong.Text = song;
this.lbConnectStatus.Text = "Connected! (HEOS Mode)";
int.TryParse(curPosStr, out int curPos);
int.TryParse(durationStr, out int duration);
if (duration > 0)
{
if (_maxDuration != duration)
{
_maxDuration = duration;
pnlProgressBar.Width = 0;
_localCurPos = curPos;
}
if (Math.Abs(_localCurPos - curPos) > 2000)
{
_localCurPos = curPos;
}
double percent = (double)_localCurPos / _maxDuration;
pnlProgressBar.Width = (int)(pnlProgressBack.ClientRectangle.Width * Math.Min(percent, 1.0));
lblTime.Text = $"{FormatTime(_localCurPos)} / {FormatTime(_maxDuration)}";
if (state == "play" && IsAVROn)
{
if (!timerProgress.Enabled) timerProgress.Start();
this.btnHeosPlayPause.BackgroundImage = global::AVRControl.Properties.Resources.PauseIcon;
}
else
{
timerProgress.Stop();
this.btnHeosPlayPause.BackgroundImage = global::AVRControl.Properties.Resources.PauseIcon;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Fehler beim Parsen der Metadaten: " + ex.Message);
}
}
public async Task UpdateHeosDetails()
{
if (string.IsNullOrEmpty(_activePid))
{
await _heosTelnet.SendAsync("heos://player/get_players");
return;
}
string command = $"heos://player/get_now_playing_media?pid={_activePid}";
await _heosTelnet.SendAsync(command);
}
}
}