-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
89 lines (80 loc) · 2.1 KB
/
Copy pathMain.cpp
File metadata and controls
89 lines (80 loc) · 2.1 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
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include"MusicPlayer.h"
using namespace std;
int main()
{
MusicPlayer player;
char* username = nullptr;
size_t len;
_dupenv_s(&username, &len, "USERNAME");
std::string user = username ? username : "";
free(username);
std::string musicPath = "C:/Users/" + user + "/Music";
player.loadMusicFromDirectory(musicPath);
std::cout << "Console Music Player\n";
std::cout << "Loaded music from: " << musicPath << "\n";
printHelp();
std::string command;
while (true)
{
player.checkAndAutoNext(); // Check if song ended and switch if needed
std::cout << "\n> ";
std::getline(std::cin, command);
try
{
if (command == "play") player.play();
else if (command == "pause") player.pause();
else if (command == "next")
{
if (player.getLoopSingle() == true)
{
player.toggleLoop();
}
player.next();
}
else if (command == "prev")
{
player.previous();
if (player.getLoopSingle() == true)
{
player.toggleLoop();
}
}
else if (command.rfind("fwd", 0) == 0)
{
int seconds = 5; // Default
std::istringstream iss(command);
std::string cmd;
iss >> cmd >> seconds;
player.seekForward(seconds);
}
else if (command.rfind("bwd", 0) == 0)
{
int seconds = 5; // Default
std::istringstream iss(command);
std::string cmd;
iss >> cmd >> seconds;
player.seekBackward(seconds);
}
else if (command == "loop") player.toggleLoop();
else if (command == "list") player.displayPlaylist();
else if (command == "info")
{
player.displayCurrentTrack();
std::cout << "Console Music Player\n";
std::cout << "Loaded music from: " << musicPath << "\n";
printHelp();
}
else if (command == "help") printHelp();
else if (command == "exit") break;
else std::cout << "Unknown command. Type 'help' for list of commands.\n";
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
}
std::cout << "Exiting...\n";
return 0;
}