This commit is contained in:
minster586
2025-08-27 06:42:45 -04:00
parent c8f6f7ff95
commit 155f8bbeab
7 changed files with 118 additions and 25 deletions

View File

@@ -122,13 +122,13 @@
//
this.restAPISettingToolStripMenuItem.Name = "restAPISettingToolStripMenuItem";
this.restAPISettingToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.restAPISettingToolStripMenuItem.Text = "Rest API Setting";
this.restAPISettingToolStripMenuItem.Text = "Setting";
this.restAPISettingToolStripMenuItem.Click += new System.EventHandler(this.restAPISettingToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem.Size = new System.Drawing.Size(157, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
@@ -166,7 +166,7 @@
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(205, 130);
this.label6.Location = new System.Drawing.Point(170, 130);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(65, 16);
this.label6.TabIndex = 5;
@@ -175,7 +175,7 @@
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(205, 84);
this.label5.Location = new System.Drawing.Point(170, 83);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(56, 16);
this.label5.TabIndex = 4;
@@ -184,7 +184,7 @@
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(205, 41);
this.label4.Location = new System.Drawing.Point(170, 39);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(48, 16);
this.label4.TabIndex = 3;
@@ -270,6 +270,7 @@
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3;
private System.Windows.Forms.MenuStrip menuStrip2;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
@@ -278,15 +279,14 @@
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;
}
}

View File

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Resources;
namespace RadioDJViewer
{
@@ -30,6 +31,7 @@ namespace RadioDJViewer
public Main()
{
InitializeComponent();
EnsureDefaultImageExists();
UpdateStatusBar();
// Auto-load profiles if profiles.json exists
AutoLoadProfiles();
@@ -37,6 +39,45 @@ namespace RadioDJViewer
apiTimer = new System.Windows.Forms.Timer();
apiTimer.Interval = 3000; // 3 seconds
apiTimer.Tick += ApiTimer_Tick;
// Set up marquee timer for title
marqueeTimer = new System.Windows.Forms.Timer();
marqueeTimer.Interval = 100; // Adjust speed as needed
marqueeTimer.Tick += MarqueeTimer_Tick;
}
private System.Windows.Forms.Timer marqueeTimer;
private int marqueeOffset = 0;
private string marqueeText = "";
private void EnsureDefaultImageExists()
{
if (!File.Exists(defaultImagePath))
{
// Try to extract from resources
var fallbackImg = Properties.Resources.fallback;
if (fallbackImg != null)
{
fallbackImg.Save(defaultImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
private void MarqueeTimer_Tick(object sender, EventArgs e)
{
if (marqueeText.Length > 0)
{
int visibleChars = 30; // Adjust for label width
if (marqueeText.Length > visibleChars)
{
marqueeOffset = (marqueeOffset + 1) % marqueeText.Length;
string display = marqueeText.Substring(marqueeOffset) + " " + marqueeText.Substring(0, marqueeOffset);
label4.Text = display.Substring(0, Math.Min(visibleChars, display.Length));
}
else
{
label4.Text = marqueeText;
}
}
}
private void ApiTimer_Tick(object sender, EventArgs e)
@@ -170,18 +211,32 @@ namespace RadioDJViewer
{
string imagePath = string.Empty;
string outputImageName = loadedProfile?.OutputImageName;
bool useFallback = false;
if (!string.IsNullOrEmpty(mainImagesFolderPath) && !string.IsNullOrEmpty(imageName))
{
imagePath = Path.Combine(mainImagesFolderPath, imageName);
if (!File.Exists(imagePath))
{
useFallback = true;
}
if (string.IsNullOrEmpty(imagePath) || !File.Exists(imagePath))
}
else
{
// Show default image if not found
if (File.Exists(defaultImagePath))
useFallback = true;
}
if (useFallback)
{
using (var img = Image.FromFile(defaultImagePath))
// Use fallback PNG from resources
var fallbackImg = Properties.Resources.fallback;
if (fallbackImg != null)
{
pictureBox1.Image = new Bitmap(img);
var resized = new Bitmap(fallbackImg, pictureBox1.Size);
pictureBox1.Image = resized;
// Save fallback image to output folder as PNG
if (!string.IsNullOrEmpty(outputFolderPath) && !string.IsNullOrEmpty(outputImageName))
{
string destPath = Path.Combine(outputFolderPath, Path.ChangeExtension(outputImageName, ".png"));
resized.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
}
}
else
@@ -192,19 +247,37 @@ namespace RadioDJViewer
}
try
{
// Display in pictureBox1
using (var img = Image.FromFile(imagePath))
{
pictureBox1.Image = new Bitmap(img);
// Copy and convert to PNG in output folder if set and output image name is set
var resized = new Bitmap(img, pictureBox1.Size);
pictureBox1.Image = resized;
// Save to output folder as PNG
if (!string.IsNullOrEmpty(outputFolderPath) && !string.IsNullOrEmpty(outputImageName))
{
string destPath = Path.Combine(outputFolderPath, Path.ChangeExtension(outputImageName, ".png"));
img.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
resized.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
catch { /* Handle errors if needed */ }
catch
{
// If loading image fails, fallback
var fallbackImg = Properties.Resources.fallback;
if (fallbackImg != null)
{
var resized = new Bitmap(fallbackImg, pictureBox1.Size);
pictureBox1.Image = resized;
if (!string.IsNullOrEmpty(outputFolderPath) && !string.IsNullOrEmpty(outputImageName))
{
string destPath = Path.Combine(outputFolderPath, Path.ChangeExtension(outputImageName, ".png"));
resized.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
}
}
else
{
pictureBox1.Image = null;
}
}
}
private void ParseAndDisplaySongInfo(string xml)
@@ -219,14 +292,16 @@ namespace RadioDJViewer
string album = doc.SelectSingleNode("//*[translate(local-name(), 'ALBUM', 'album')='album']")?.InnerText;
string albumArt = doc.SelectSingleNode("//*[translate(local-name(), 'ALBUMART', 'albumart')='albumart']")?.InnerText;
label4.Text = !string.IsNullOrWhiteSpace(title) ? title : "No title";
marqueeText = !string.IsNullOrWhiteSpace(title) ? title : "No title";
marqueeOffset = 0;
marqueeTimer.Start();
label5.Text = !string.IsNullOrWhiteSpace(artist) ? artist : "No artist";
label6.Text = !string.IsNullOrWhiteSpace(album) ? album : "No album";
// Write to output files
if (!string.IsNullOrEmpty(outputFolderPath))
{
File.WriteAllText(Path.Combine(outputFolderPath, "title.txt"), label4.Text);
File.WriteAllText(Path.Combine(outputFolderPath, "title.txt"), marqueeText);
File.WriteAllText(Path.Combine(outputFolderPath, "artist.txt"), label5.Text);
File.WriteAllText(Path.Combine(outputFolderPath, "album.txt"), label6.Text);
}
@@ -243,7 +318,9 @@ namespace RadioDJViewer
}
catch
{
label4.Text = "No title";
marqueeText = "No title";
marqueeOffset = 0;
marqueeTimer.Start();
label5.Text = "No artist";
label6.Text = "No album";
pictureBox1.Image = null;
@@ -270,7 +347,7 @@ namespace RadioDJViewer
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
string message = $"RadioDJViewer\nVersion: {version}\nGitHub: https://github.com/yourusername/RadioDJViewer";
string message = $"RadioDJViewer\nVersion: {version}\nGitHub: https://git.smartcraft.me/minster586/RadioDJViewer";
MessageBox.Show(message, "About RadioDJViewer", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

View File

@@ -124,7 +124,7 @@
<data name="toolStripStatusLabel2.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAIAAAACABAMAAAAxEHz4AAAABGdBTUEAALGPC/xhBQAAAANQTFRFJn8A
Mx1isQAAAAlwSFlzAAAOvgAADr4B6kKxwAAAAB9JREFUaN7twTEBAAAAwqD1T20IX6AAAAAAAAAAAD4D
Mx1isQAAAAlwSFlzAAAOvAAADrwBlbxySQAAAB9JREFUaN7twTEBAAAAwqD1T20IX6AAAAAAAAAAAD4D
IIAAAT2Y3yoAAAAASUVORK5CYII=
</value>
</data>

View File

@@ -60,6 +60,16 @@ namespace RadioDJViewer.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap fallback {
get {
object obj = ResourceManager.GetObject("fallback", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="fallback" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fallback.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="green" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

View File

@@ -100,5 +100,8 @@
<ItemGroup>
<None Include="Resources\red.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\fallback.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB