Files
SammelmappeOOP/AudioPlayer/AudioPlayer.cs
2024-07-25 15:47:46 +02:00

56 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace AudioPlayer
{
internal class AudioPlayer
{
private int id;
private AudioFile[] player;
private Random rnd = new Random();
public AudioPlayer(int cnt)
{
//this.id = id;
this.player = new AudioFile[cnt];
}
public void AddFile(AudioFile file)
{
for (int i = 0; i < player.Length; i++)
{
if (player[i] is null)
{
this.player[i] = file;
break;
}
}
}
public void RemoveFile(int id)
{
if (id >= 0 && id < player.Length)
{
player[id] = null;
}
}
public void Play(AudioFile file)
{
file.Play();
}
public void PlayAll()
{
player = player.OrderBy(i => rnd.Next(player.Length)).ToArray();
for (int i = 0; i < player.Length; i++)
{
if (player[i] is not null)
{
player[i].Play();
}
}
}
}
}