-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathPlayerHarness.cs
More file actions
91 lines (83 loc) · 3.48 KB
/
PlayerHarness.cs
File metadata and controls
91 lines (83 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using NetCoreAudio;
namespace DemoHarness
{
internal static class PlayerHarness
{
public static async Task InteractWithPlayer()
{
var player = new Player();
player.PlaybackFinished += OnPlaybackFinished;
ShowFileEntryPrompt();
var fileName = Console.ReadLine();
ShowInstruction();
while (true)
{
var command = Console.ReadLine();
try
{
switch (command)
{
case "play":
Console.WriteLine($"Playing {fileName}");
await player.Play(fileName);
Console.WriteLine(player.Playing ? "Playback started" : "Could not start the playback");
break;
case "pause":
await player.Pause();
Console.WriteLine(player.Paused ? "Playback paused" : "Could not pause playback");
break;
case "resume":
await player.Resume();
Console.WriteLine(player.Playing && !player.Paused ? "Playback resumed" : "Could not resume playback");
break;
case "stop":
await player.Stop();
Console.WriteLine(!player.Playing ? "Playback stopped" : "Could not stop the playback");
break;
case "change":
await player.Stop();
ShowFileEntryPrompt();
fileName = Console.ReadLine();
ShowInstruction();
break;
case "volume":
Console.WriteLine("Enter new volume in percent");
byte volume = Convert.ToByte(Console.ReadLine());
await player.SetVolume(volume);
ShowInstruction();
break;
case "exit":
break;
default:
Console.WriteLine("Unknown command!");
break;
}
if (command == "exit") break;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
static void ShowFileEntryPrompt()
{
Console.WriteLine("Please enter the full path to the file you would like to play:");
}
static void ShowInstruction()
{
Console.WriteLine("You can manipulate the player with the following commands:");
Console.WriteLine("play - Play the specified file from the start");
Console.WriteLine("pause - Pause the playback");
Console.WriteLine("resume - Resume the playback");
Console.WriteLine("stop - Stop the playback");
Console.WriteLine("change - Change the file name");
Console.WriteLine("volume - Set the volume");
Console.WriteLine("exit - Exit the app");
}
static void OnPlaybackFinished(object sender, EventArgs e)
{
Console.WriteLine("Playback finished");
}
}
}