56 lines
1.3 KiB
C#
56 lines
1.3 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();
|
|
|
|
public void PlaySound(byte[] audioBlob)
|
|
{
|
|
string tempFile = System.IO.Path.Combine(
|
|
System.IO.Path.GetTempPath(),
|
|
Guid.NewGuid() + ".mp3");
|
|
|
|
|
|
|
|
File.WriteAllBytes(tempFile, audioBlob);
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|