13 Commits
8 changed files with 151 additions and 40 deletions

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>PAiPlayer - A school project that helps me learn C++</description>
<description>ClickPlay - a simple C++ music player</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
BIN
View File
Binary file not shown.
-6
View File
@@ -8,19 +8,13 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x64.ActiveCfg = Debug|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x64.Build.0 = Debug|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x86.ActiveCfg = Debug|Win32
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x86.Build.0 = Debug|Win32
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x64.ActiveCfg = Release|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x64.Build.0 = Release|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x86.ActiveCfg = Release|Win32
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+1 -1
View File
@@ -22,7 +22,7 @@
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{c734fda7-262e-4202-8f4e-5e3031cb9935}</ProjectGuid>
<RootNamespace>EasyAudioPlayer</RootNamespace>
<RootNamespace>ClickPlay</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>ClickPlay</ProjectName>
</PropertyGroup>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+147 -31
View File
@@ -43,7 +43,7 @@ wstring ext[EXT_LENGTH] = { L"mp3", L"wav" };
//PATH VARS
vector<WIN32_FIND_DATA> files;
wstring path;
int selected = -1;
double selected = -1;
//STATE VARS
/*
@@ -53,7 +53,8 @@ int selected = -1;
* 2 - playback paused
*/
int currentState = -1;
BOOL isAutoPlayEnabled = TRUE;
BOOL isOnClickPlayEnabled = TRUE;
BOOL isAutoPlayEnabled = FALSE;
BOOL isLoopEnabled = FALSE;
BOOL isQueued = FALSE;
BOOL showExtensions = FALSE;
@@ -108,7 +109,7 @@ int WINAPI WinMain(HINSTANCE currentInst, HINSTANCE previousInst, LPSTR lpCmdLin
//INITIALIZE MESSAGE LOOP
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, shortcuts, &msg)) {
if (!TranslateAccelerator(mainWindow, shortcuts, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@@ -161,6 +162,7 @@ void UnloadSelection() {
* -1 - invalid index
* -2 - file not found
* -3 - path not loaded
* -4 - file loading error
*/
int LoadSelection(int index) {
UnloadSelection();
@@ -177,7 +179,11 @@ int LoadSelection(int index) {
wstring fullCommandS = L"open \"" + fullPath + L"\" type mpegvideo alias mp3";
LPCWSTR fullCommand = fullCommandS.c_str();
mciSendString(fullCommand, NULL, 0, mainWindow);
if (mciSendString(fullCommand, NULL, 0, mainWindow) != 0) {
UnloadSelection();
MessageBox(mainWindow, L"Nieznany b³¹d uniemo¿liwia odtworzenie tego pliku. SprawdŸ czy plik nie jest uszkodzony.", L"B³¹d wczytywania", MB_ICONERROR);
return -4;
}
selected = index;
return 0;
}
@@ -285,16 +291,23 @@ int FolderBrowseDialog(HWND window) {
}
//SEARCH DIRECTORY
void SearchDir(wstring phrase) {
/*ERROR CODES
* -1 - no files found
* -2 - LoadDir error
* -3 - empty input
*/
int SearchDir(wstring phrase) {
//PERFORM CHECKING
if (path.empty()) {
return;
return -2;
}
//RELOAD DIR
LoadDir(path);
if (LoadDir(path) != 0) {
return -2;
}
//PREPARE
if (phrase.empty()) {
return;
return -3;
}
vector<WIN32_FIND_DATA> results;
//GET FILES
@@ -305,26 +318,27 @@ void SearchDir(wstring phrase) {
}
if (results.empty()) {
MessageBox(mainWindow, L"Nie znaleziono plików zawieraj¹cych wpisan¹ frazê.", L"Brak plików", MB_ICONEXCLAMATION);
return;
return -1;
}
std::sort(results.begin(), results.end(), alphabeticSort);
files = results;
//ADD FILTERED CONTENT
GenerateList(files);
return 0;
}
//GET SEARCH PHRASE FROM searchBox
wstring GetSearchPhrase() {
__int64 searchLength = SendMessage(searchBox, WM_GETTEXTLENGTH, 0, NULL);
TCHAR* searchPhrase = new TCHAR[static_cast<__int64>(searchLength) << 1];
SendMessage(searchBox, WM_GETTEXT, static_cast<__int64>(searchLength) << 1, (LPARAM)searchPhrase);
searchPhrase[searchLength] = _T('\0');
double searchLength = SendMessage(searchBox, WM_GETTEXTLENGTH, 0, NULL);
TCHAR* searchPhrase = new TCHAR[searchLength + 1];
SendMessage(searchBox, WM_GETTEXT, searchLength + 1, (LPARAM)searchPhrase);
searchPhrase[(int)searchLength] = _T('\0');
return wstring(searchPhrase);
}
//MESSAGE LOOP
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
int windowId, windowEvent;
int windowId, windowEvent, randIndex;
switch (msg) {
case WM_CLOSE:
DestroyWindow(hwnd);
@@ -355,15 +369,22 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (windowEvent == LBN_SELCHANGE) {
if (currentState == 1 || currentState == 2) { currentState = 1; isQueued = TRUE; }
if (LoadSelection(GetIndex()) == 0) {
if (isAutoPlayEnabled == TRUE) {
if (isOnClickPlayEnabled == TRUE) {
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
}
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
}
break;
case IDC_SEARCHBTN:
SearchDir(GetSearchPhrase());
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
if (SearchDir(GetSearchPhrase()) == -2) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
break;
case IDC_PLAYBTN:
switch (currentState) {
@@ -371,6 +392,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (LoadSelection(GetIndex()) == 0) {
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
break;
case 1:
SendMessage(mainWindow, STATE_CHANGE, 2, NULL);
@@ -382,7 +406,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
break;
case IDC_STOPBTN:
isQueued = FALSE;
SendMessage(mainWindow, MM_MCINOTIFY, 0, 0);
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
break;
case IDM_EXIT:
SendMessage(mainWindow, WM_CLOSE, NULL, NULL);
@@ -395,17 +420,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
if (SendMessage(searchBox, WM_GETTEXTLENGTH, 0, 0) > 0) {
SearchDir(GetSearchPhrase());
if (SearchDir(GetSearchPhrase()) == -2) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
}
break;
case ID_OPCJE_ONCLICK:
if (isAutoPlayEnabled) {
if (isOnClickPlayEnabled) {
CheckMenuItem(menuBar, ID_OPCJE_ONCLICK, MF_UNCHECKED);
isAutoPlayEnabled = FALSE;
isOnClickPlayEnabled = FALSE;
}
else {
CheckMenuItem(menuBar, ID_OPCJE_ONCLICK, MF_CHECKED);
isAutoPlayEnabled = TRUE;
isOnClickPlayEnabled = TRUE;
}
break;
case ID_OPCJE_LOOP:
@@ -431,6 +458,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
if (!path.empty() && !files.empty()) {
GenerateList(files);
if (selected != -1) {
SendMessage(filesListCtrl, LB_SETCURSEL, selected, 0);
}
}
break;
case ID_PLIK_CLOSEDIR:
@@ -450,15 +480,63 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
//GET SEED
srand(time(NULL));
//LOAD AND PLAY
LoadSelection(rand() % files.size());
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
randIndex = rand() % files.size();
if (LoadSelection(randIndex) == 0) {
SendMessage(filesListCtrl, LB_SETCURSEL, randIndex, 0);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
break;
case ID_OPCJE_AUTOPLAY:
if (isAutoPlayEnabled) {
CheckMenuItem(menuBar, ID_OPCJE_AUTOPLAY, MF_UNCHECKED);
isAutoPlayEnabled = FALSE;
}
else {
CheckMenuItem(menuBar, ID_OPCJE_AUTOPLAY, MF_CHECKED);
isAutoPlayEnabled = TRUE;
}
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
break;
}
break;
case MM_MCINOTIFY:
if (!isQueued) {
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
if (isAutoPlayEnabled) {
if (selected != -1 && !(selected + 1 > files.size() - 1)) {
if (LoadSelection(selected + 1) == 0) {
SendMessage(filesListCtrl, LB_SETCURSEL, selected, 0);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
}
else if(isLoopEnabled && selected != -1) {
if (LoadSelection(0) == 0) {
SendMessage(filesListCtrl, LB_SETCURSEL, selected, 0);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
}
else {
if (selected != -1) {
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
}
}
}
else {
if (selected != -1) {
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
}
}
}
else {
isQueued = FALSE;
@@ -502,18 +580,25 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
case 1:
if (!path.empty() && selected != -1) {
int playerState = 0;
if (currentState == 2) {
mciSendString(L"resume mp3", NULL, 0, mainWindow);
playerState = mciSendString(L"resume mp3", NULL, 0, mainWindow);
}
else {
if (isLoopEnabled) {
mciSendString(L"play mp3 repeat", NULL, 0, mainWindow);
if (isLoopEnabled && !isAutoPlayEnabled) {
playerState = mciSendString(L"play mp3 repeat", NULL, 0, mainWindow);
}
else {
mciSendString(L"play mp3 notify", NULL, 0, mainWindow);
playerState = mciSendString(L"play mp3 notify", NULL, 0, mainWindow);
}
}
if (playerState != 0) {
MessageBox(mainWindow, L"Nie uda³o siê odtworzyæ wskazanego pliku. SprawdŸ czy plik nie jest uszkodzony.", L"B³¹d odtwarzania", MB_ICONERROR);
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
break;
}
EnableWindow(filesListCtrl, TRUE);
EnableWindow(playButton, TRUE);
EnableWindow(stopButton, TRUE);
@@ -574,5 +659,36 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
//SORTING FUNCTION
bool alphabeticSort(WIN32_FIND_DATA a, WIN32_FIND_DATA b) {
return std::tolower(wstring(a.cFileName).at(0)) < std::tolower(wstring(b.cFileName).at(0));
wstring aStr = a.cFileName;
wstring bStr = b.cFileName;
wstring aBuf;
wstring bBuf;
int aNum = 0;
int bNum = 0;
for (int i = 0; i < aStr.size(); i++) {
if (std::isdigit(static_cast<unsigned char>(aStr.at(i)))) {
aBuf += aStr.at(i);
}
else {
break;
}
}
for (int i = 0; i < bStr.size(); i++) {
if (std::isdigit(static_cast<unsigned char>(bStr.at(i)))) {
bBuf += bStr.at(i);
}
else {
break;
}
}
if (!aBuf.empty()) {
aNum = std::stoi(aBuf);
}
if (!bBuf.empty()) {
bNum = std::stoi(bBuf);
}
if (aNum != 0 || bNum != 0) {
return aNum < bNum;
}
return std::tolower(aStr.at(0)) < std::tolower(bStr.at(0));
}
+2 -1
View File
@@ -20,6 +20,7 @@
#define ID_PLIK_OPENDIR 32780
#define ID_AKCJE_RANDOM 32781
#define ID_OPCJE_SHOWEXT 32782
#define ID_OPCJE_AUTOPLAY 32783
#define IDC_STATIC -1
// Next default values for new objects
@@ -28,7 +29,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32783
#define _APS_NEXT_COMMAND_VALUE 32784
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif