Delicious Cake
Delicious Cake
CC#
Created by Delicious Cake on 11/16/2024 in #help
ListView column help (How to autosize, align content and add column lines?)
No description
2 replies
CC#
Created by Delicious Cake on 5/18/2024 in #help
✅ How to play an MP3 from byte data array instead of writing it to a file and then playing it?
Hey, anyone know how I can play an MP3 directly from a byte array? This is what I currently have which works but I'd like to avoid writing it to an .mp3 file as there's no point in keeping it and it feels wrong to Write > Play > Delete if I can just play it directly from the byte array.
await File.WriteAllBytesAsync($"{voiceClip.Id}.mp3", voiceClip.ClipData.ToArray());
var reader = new Mp3FileReader($"{voiceClip.Id}.mp3");
var waveOut = new WaveOut(); // or WaveOutEvent()
waveOut.Init(reader);
waveOut.Play();
await File.WriteAllBytesAsync($"{voiceClip.Id}.mp3", voiceClip.ClipData.ToArray());
var reader = new Mp3FileReader($"{voiceClip.Id}.mp3");
var waveOut = new WaveOut(); // or WaveOutEvent()
waveOut.Init(reader);
waveOut.Play();
4 replies
CC#
Created by Delicious Cake on 5/18/2024 in #help
✅ ERROR: The calling thread cannot access this object because a different thread owns it.
Hey, I'm getting this error The calling thread cannot access this object because a different thread owns it. from the following method when trying to add a Run element to a RichTextBox I've tried Googling a ton and even tried ChatGPT to see if it could fix it for me, all answers point to use chatRichTextBox.Dispatcher.Invoke but it still fails, any ideas?
private void AddChatMessage(string username, string message, System.Drawing.Color usernameColor)
{
System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromArgb(usernameColor.A, usernameColor.R, usernameColor.G, usernameColor.B);

var usernameRun = new Run(username)
{
Foreground = new SolidColorBrush(mediaColor),
FontWeight = FontWeights.Bold
};
var messageRun = new Run(": " + message)
{
Foreground = Brushes.White
};

var paragraph = new Paragraph();
paragraph.Inlines.Add(usernameRun);
paragraph.Inlines.Add(messageRun);

// Ensure the UI update is done on the UI thread
chatRichTextBox.Dispatcher.Invoke(() =>
{
chatRichTextBox.Document.Blocks.Add(paragraph);
chatRichTextBox.ScrollToEnd();
});
}
private void AddChatMessage(string username, string message, System.Drawing.Color usernameColor)
{
System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromArgb(usernameColor.A, usernameColor.R, usernameColor.G, usernameColor.B);

var usernameRun = new Run(username)
{
Foreground = new SolidColorBrush(mediaColor),
FontWeight = FontWeights.Bold
};
var messageRun = new Run(": " + message)
{
Foreground = Brushes.White
};

var paragraph = new Paragraph();
paragraph.Inlines.Add(usernameRun);
paragraph.Inlines.Add(messageRun);

// Ensure the UI update is done on the UI thread
chatRichTextBox.Dispatcher.Invoke(() =>
{
chatRichTextBox.Document.Blocks.Add(paragraph);
chatRichTextBox.ScrollToEnd();
});
}
23 replies