-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMusic.cpp
95 lines (79 loc) · 1.54 KB
/
CMusic.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
#include "StdAfx.h"
#include "CMusic.h"
string CMusic::ALIAS_NAME = "MEDIA_MP3";
CMusic::CMusic()
{
isOpen = false;
setMediaName("Vertigo.mp3");
open_cmd = "OPEN " + mediaName + " TYPE MPEGVideo ALIAS " + ALIAS_NAME;
status_cmd = "status " + ALIAS_NAME + " mode";
play_cmd = "PLAY " + ALIAS_NAME + " FROM 0";
close_cmd = "CLOSE " + ALIAS_NAME;
}
CMusic::CMusic(string mediaName)
{
isOpen = false;
setMediaName(mediaName);
open_cmd = "OPEN " + mediaName + " ALIAS " + ALIAS_NAME;
status_cmd = "status " + ALIAS_NAME + " mode";
play_cmd = "PLAY " + ALIAS_NAME + " FROM 0";
close_cmd = "CLOSE " + ALIAS_NAME;
}
//发送信息给MCI
bool CMusic::SendMciCmd(string cmd)
{
//播放多媒体文件的API指令
if (!mciSendString(cmd.c_str(), NULL, 0, 0))
{
return true;
}
return false;
}
//从MCI获取信息
string CMusic::GetMciStatus(string cmd)
{
char message[20];
mciSendString(cmd.c_str(), message, 20, 0);
string str(message);
return str;
}
void CMusic::ClosePlayer()
{
if (isOpen)
{
SendMciCmd(close_cmd);
isOpen = false;
}
}
void CMusic::OpenMediaFile()
{
ClosePlayer();
SendMciCmd(open_cmd);
isOpen = true;
}
void CMusic::PlayMediaFile()
{
if (isOpen)
{
SendMciCmd(play_cmd);
}
}
void CMusic::Play()
{
OpenMediaFile();
PlayMediaFile();
}
void CMusic::Stop()
{
ClosePlayer();
}
bool CMusic::isStopped()
{
string result = "";
result = GetMciStatus(status_cmd); //获取音乐状态
if (result == "stopped")
{
return true;
}
return false;
}