omgMajk
Member
- Joined
- Mar 9, 2021
- Messages
- 5
- Programming Experience
- Beginner
So I have this program that takes the title of the Spotify window and prints it to the console. The code is mostly stolen from Stack Overflow but the problem I'm having is that when certain characters are played, the Console.WriteLine() makes a windows system sound that I'm trying to get rid of.
Now, whenever I play certain songs by a band that is not properly formated on Spotify, the console makes this noise. But I still want to display most things like swedish and danish characters. Song name in question in image below. Any solution to this?
Spotify Title Program:
using System;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
namespace SpotifyTest
{
class Program
{
public string GetSpotifyTrackInfo()
{
var proc = Process.GetProcessesByName("Spotify").FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle));
if (proc == null)
{
return "Spotify is not running!";
}
if (string.Equals(proc.MainWindowTitle, "Spotify Premium", StringComparison.InvariantCultureIgnoreCase) || string.Equals(proc.MainWindowTitle, "Spotify", StringComparison.InvariantCultureIgnoreCase))
{
return "Paused";
}
return proc.MainWindowTitle;
}
static void Main(string[] args)
{
Program x = new Program();
while (true)
{
string songName = x.GetSpotifyTrackInfo();
//songName = Regex.Replace(songName, "[^A-Za-z0-9 -]", ""); //Not good since doesn't display swedish
Thread.Sleep(2000);
Console.Clear();
Console.WriteLine(songName);
}
}
}
}
Now, whenever I play certain songs by a band that is not properly formated on Spotify, the console makes this noise. But I still want to display most things like swedish and danish characters. Song name in question in image below. Any solution to this?