Music Player Hinzugefügt
This commit is contained in:
+26
-2
@@ -13,7 +13,7 @@ namespace Casino
|
||||
{
|
||||
private readonly MediaPlayer player = new MediaPlayer();
|
||||
|
||||
public void Play(byte[] audioBlob)
|
||||
public void PlaySound(byte[] audioBlob)
|
||||
{
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
@@ -26,6 +26,30 @@ namespace Casino
|
||||
player.Open(new Uri(tempFile));
|
||||
player.Play();
|
||||
}
|
||||
|
||||
|
||||
private bool isPlaying = false;
|
||||
private readonly MediaPlayer musicPlayer = new();
|
||||
|
||||
public void PlayMusic(byte[] audioBlob)
|
||||
{
|
||||
if (isPlaying)
|
||||
return;
|
||||
|
||||
isPlaying = true;
|
||||
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
Guid.NewGuid() + ".mp3");
|
||||
|
||||
System.IO.File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
musicPlayer.MediaEnded += (s, e) =>
|
||||
{
|
||||
isPlaying = false;
|
||||
};
|
||||
|
||||
musicPlayer.Open(new Uri(tempFile));
|
||||
musicPlayer.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user