add Programmyday form github
This commit is contained in:
17
AudioPlayer/AudioFile.cs
Normal file
17
AudioPlayer/AudioFile.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Enumeration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AudioPlayer
|
||||
{
|
||||
abstract class AudioFile
|
||||
{
|
||||
protected string fileName;
|
||||
protected string speicherOrt;
|
||||
|
||||
public abstract void Play();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
AudioPlayer/AudioPlayer.csproj
Normal file
10
AudioPlayer/AudioPlayer.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
21
AudioPlayer/FLACFile.cs
Normal file
21
AudioPlayer/FLACFile.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AudioPlayer
|
||||
{
|
||||
internal class FLACFile : AudioFile
|
||||
{
|
||||
public FLACFile(string fileName, string speicherOrt)
|
||||
{
|
||||
this.fileName = fileName;
|
||||
this.speicherOrt = speicherOrt;
|
||||
}
|
||||
public override void Play()
|
||||
{
|
||||
Console.WriteLine($"{this.fileName} von {this.speicherOrt} vom Typ FLAC wird abgespielt.");
|
||||
}
|
||||
}
|
||||
}
|
||||
21
AudioPlayer/MP3File.cs
Normal file
21
AudioPlayer/MP3File.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AudioPlayer
|
||||
{
|
||||
internal class MP3File : AudioFile
|
||||
{
|
||||
public MP3File(string fileName, string speicherOrt)
|
||||
{
|
||||
this.fileName = fileName;
|
||||
this.speicherOrt = speicherOrt;
|
||||
}
|
||||
public override void Play()
|
||||
{
|
||||
Console.WriteLine($"{this.fileName} von {this.speicherOrt} vom Typ MP3 wird abgespielt.");
|
||||
}
|
||||
}
|
||||
}
|
||||
20
AudioPlayer/Program.cs
Normal file
20
AudioPlayer/Program.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace AudioPlayer
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
AudioFile song1 = new MP3File("An Ocean Between Us","bungabunga");
|
||||
AudioFile song2 = new FLACFile("Lie to me","ungabunga");
|
||||
AudioFile song3 = new MP3File("Fly high", "ungabungabunga");
|
||||
AudioFile song4 = new WAVFile("Forever", "bungaunga");
|
||||
AudioPlayer player = new AudioPlayer(5);
|
||||
player.AddFile(song1);
|
||||
player.AddFile(song2);
|
||||
player.AddFile(song3);
|
||||
player.AddFile(song4);
|
||||
player.PlayAll();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
21
AudioPlayer/WAVFile.cs
Normal file
21
AudioPlayer/WAVFile.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AudioPlayer
|
||||
{
|
||||
internal class WAVFile : AudioFile
|
||||
{
|
||||
public WAVFile(string fileName, string speicherOrt)
|
||||
{
|
||||
this.fileName = fileName;
|
||||
this.speicherOrt = speicherOrt;
|
||||
}
|
||||
public override void Play()
|
||||
{
|
||||
Console.WriteLine($"{this.fileName} von {this.speicherOrt} vom Typ WAV wird abgespielt.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user