Looping sounds und hintergrund musik für slots
This commit is contained in:
+21
-17
@@ -13,6 +13,8 @@ namespace Casino
|
||||
{
|
||||
private readonly MediaPlayer player = new MediaPlayer();
|
||||
|
||||
public Audioplayer() { player.MediaEnded += Player_MediaEnded; }
|
||||
|
||||
public void PlaySound(byte[] audioBlob)
|
||||
{
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
@@ -27,29 +29,31 @@ namespace Casino
|
||||
player.Play();
|
||||
}
|
||||
|
||||
private bool isPlaying = false;
|
||||
private readonly MediaPlayer musicPlayer = new();
|
||||
|
||||
public void PlayMusic(byte[] audioBlob)
|
||||
private void Player_MediaEnded(object? sender, EventArgs e)
|
||||
{
|
||||
if (isPlaying)
|
||||
return;
|
||||
|
||||
isPlaying = true;
|
||||
player.Position = TimeSpan.Zero;
|
||||
player.Play();
|
||||
}
|
||||
|
||||
public void PlayLoopingSound(byte[] audioBlob)
|
||||
{
|
||||
string tempFile = System.IO.Path.Combine(
|
||||
System.IO.Path.GetTempPath(),
|
||||
Guid.NewGuid() + ".mp3");
|
||||
"background.mp3");
|
||||
|
||||
System.IO.File.WriteAllBytes(tempFile, audioBlob);
|
||||
File.WriteAllBytes(tempFile, audioBlob);
|
||||
|
||||
musicPlayer.MediaEnded += (s, e) =>
|
||||
{
|
||||
isPlaying = false;
|
||||
};
|
||||
player.Open(new Uri(tempFile));
|
||||
|
||||
musicPlayer.Open(new Uri(tempFile));
|
||||
musicPlayer.Play();
|
||||
player.MediaEnded -= Player_MediaEnded;
|
||||
player.MediaEnded += Player_MediaEnded;
|
||||
|
||||
player.Play();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
player.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user