From da0b8189d7c34db489131bee7fe4bb15c00bd935 Mon Sep 17 00:00:00 2001 From: "NBTEMP\\bib" Date: Sat, 12 Sep 2026 17:08:21 +0200 Subject: [PATCH] =?UTF-8?q?Looping=20sounds=20und=20hintergrund=20musik=20?= =?UTF-8?q?f=C3=BCr=20slots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Casino/Audioplayer.cs | 38 +++++++++++++++++++++----------------- Casino/MainWindow.xaml | 1 - Casino/MainWindow.xaml.cs | 7 ------- Casino/Slots.xaml.cs | 12 +++++++++--- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Casino/Audioplayer.cs b/Casino/Audioplayer.cs index 41023a3..732abf4 100644 --- a/Casino/Audioplayer.cs +++ b/Casino/Audioplayer.cs @@ -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(); } - } +} } diff --git a/Casino/MainWindow.xaml b/Casino/MainWindow.xaml index d7533fb..8797d74 100644 --- a/Casino/MainWindow.xaml +++ b/Casino/MainWindow.xaml @@ -18,7 +18,6 @@