add Programmyday form github
This commit is contained in:
55
AudioPlayer/AudioPlayer.cs
Normal file
55
AudioPlayer/AudioPlayer.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user