Files
WIR-MACHEN-ALLE-ARM/Casino/Audioplayer.cs
T
2026-09-14 18:43:16 +02:00

82 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Casino
{
class Audioplayer
{
private readonly MediaPlayer player = new MediaPlayer();
private readonly MediaPlayer shortplayer = new MediaPlayer();
public Audioplayer() { shortplayer.MediaEnded += Player_MediaEnded; }
public void PlaySound(byte[] audioBlob)
{
string tempFile = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
".mp3");
File.WriteAllBytes(tempFile, audioBlob);
shortplayer.Open(new Uri(tempFile));
shortplayer.Play();
}
private void Player_MediaEnded(object? sender, EventArgs e)
{
player.Position = TimeSpan.Zero;
player.Play();
}
public void PlayLoopingSound(byte[] audioBlob)
{
string tempFile = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
"Hintergrundmusik.mp3");
player.Volume = 0.1;
File.WriteAllBytes(tempFile, audioBlob);
player.Open(new Uri(tempFile));
player.MediaEnded -= Player_MediaEnded;
player.MediaEnded += Player_MediaEnded;
player.Play();
}
public void PlayLoopingSound_2(byte[] audioBlob)
{
string tempFile = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
"Hintergrundmusik_Bus.mp3");
player.Volume = 0.1;
File.WriteAllBytes(tempFile, audioBlob);
player.Open(new Uri(tempFile));
player.MediaEnded -= Player_MediaEnded;
player.MediaEnded += Player_MediaEnded;
player.Play();
}
public void Stop()
{
player.Stop();
}
}
}