Looping sounds und hintergrund musik für slots
This commit is contained in:
+20
-16
@@ -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) =>
|
||||
player.Open(new Uri(tempFile));
|
||||
|
||||
player.MediaEnded -= Player_MediaEnded;
|
||||
player.MediaEnded += Player_MediaEnded;
|
||||
|
||||
player.Play();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
isPlaying = false;
|
||||
};
|
||||
|
||||
musicPlayer.Open(new Uri(tempFile));
|
||||
musicPlayer.Play();
|
||||
player.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
<Grid>
|
||||
<Button Content="Slots" HorizontalAlignment="Left" Height="39" Margin="65,114,0,0" VerticalAlignment="Top" Width="93" Click="Slots_Click"/>
|
||||
<Button Content="sound" HorizontalAlignment="Left" Height="39" Margin="65,193,0,0" VerticalAlignment="Top" Width="93" Click="Sound_Click"/>
|
||||
<Button Content="Blackjack" HorizontalAlignment="Left" Margin="221,114,0,0" VerticalAlignment="Top" Height="40" Width="79" Click="Blackjack_Click"/>
|
||||
<Button Content="Busfahrer" HorizontalAlignment="Left" Margin="221,193,0,0" VerticalAlignment="Top" Height="40" Width="79" Click="Busfahrer_Click"/>
|
||||
|
||||
|
||||
@@ -28,13 +28,6 @@ namespace Casino
|
||||
slotsWindow.Show();
|
||||
}
|
||||
|
||||
private void Sound_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Database data = new Database();
|
||||
byte[] blobData = data.GetSound(2);
|
||||
var audioService = new Audioplayer();
|
||||
audioService.PlayMusic(blobData);
|
||||
}
|
||||
|
||||
private void Blackjack_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Casino
|
||||
Database db = new Database();
|
||||
private List<Byte[]> AlleBilder;
|
||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||
Audioplayer audio = new Audioplayer();
|
||||
private int[,] currentSlot = new int[3, 6];
|
||||
|
||||
|
||||
@@ -62,8 +63,7 @@ namespace Casino
|
||||
|
||||
};
|
||||
Konto.Text = users[MainWindow.currentUser].Geld.ToString();
|
||||
|
||||
|
||||
audio.PlayLoopingSound(db.GetSound(2));
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ namespace Casino
|
||||
|
||||
private void Hauptmenue(object sender, RoutedEventArgs e)
|
||||
{
|
||||
audio.Stop();
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -311,6 +312,11 @@ namespace Casino
|
||||
}
|
||||
}
|
||||
|
||||
void PlayWinSound()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user