-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
104 lines (89 loc) · 2.79 KB
/
main.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include <tchar.h>
#include <iostream>
#include <regex>
#include <conio.h>
#include <System.DateUtils.hpp>
#include "MP3Mod.h"
#include "OleUtils.h"
using std::wcout;
using std::wcerr;
using std::endl;
using std::flush;
using std::wregex;
using std::wcmatch;
using std::regex_match;
extern String StripFileExt( String Val );
// https://www.codeguru.com/multimedia/simple-c-mp3-player-class/
int _tmain(int argc, _TCHAR* argv[])
{
if ( argc >= 2 ) {
try {
TOleSession OleSession;
Mp3 mp3;
/*
wcout << L"Volume: " << mp3.GetVolume() << L" dB" << endl;
mp3.SetVolume( -10 ); // <-- Set to -10 dB
wcout << L"New volume level: " << mp3.GetVolume() << L" dB" << endl;
*/
for ( int i = 1 ; i < argc ; ++i ) {
wcout << L"Loading: \'" << argv[i] << L'\'' << endl;
mp3.LoadFromFile( argv[i] );
TDateTime const Duration { IncMilliSecond( {}, mp3.GetDuration() / 10000 ) };
wcout << L"Duration: " << Duration.TimeString() << endl;
wcout << L"Duration in 1/10000 sec: " << mp3.GetDuration() << endl;
wcout << L"Now playing (press any key to stop)" << endl;
mp3.Play();
long EvCode {};
int n {};
for ( ; !mp3.WaitForCompletion( 100, &EvCode ) ; ++n ) {
if ( kbhit() ) {
getch();
break;
}
if ( !( n % 5 ) ) {
wcout << L"." << flush;
}
}
if ( n ) {
wcout << endl;
}
mp3.Stop();
wcout << L"End playing \'" << argv[i] << L'\'' << endl;
}
}
catch ( Exception const & E ) {
wcerr << E.Message.c_str() << endl;
}
catch ( std::exception const & e ) {
wcerr << e.what() << endl;
}
catch ( ... ) {
wcerr << L"Unknown exception" << endl;
}
}
else {
wcerr << L"Use:\n "
<< LowerCase(
StripFileExt( ExtractFileName( String( argv[0] ) ) )
)
<< L" [mp3 file name]" << endl;
}
//wcout << L"Press a key" << endl;
//getch();
return 0;
}
//---------------------------------------------------------------------------
String StripFileExt( String Val )
{
wregex re( L"^(.*\?).\\w+$" );
wcmatch m;
if ( regex_match( Val.c_str(), m, re ) ) {
return m[1].str().c_str();
}
return Val;
}
//---------------------------------------------------------------------------