| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  | #include "..\etools.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | #include <mmsystem.h>
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | #include "..\Win\MciPlayer.h"
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | typedef std::pair<UINT, MciPlayer *> Music; | 
					
						
							|  |  |  | typedef std::map<UINT, MciPlayer *> MusicList; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | static MusicList& getMciPlayerList() | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	static MusicList s_List; | 
					
						
							|  |  |  | 	return s_List; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | UINT e2d::EMusicUtils::playMusic(const EString & musicFilePath, int repeatTimes) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	UINT nRet = preloadMusic(musicFilePath); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	if (nRet) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		getMciPlayerList()[nRet]->play(repeatTimes); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	return nRet; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | UINT e2d::EMusicUtils::playMusic(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension, int repeatTimes) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	UINT nRet = preloadMusic(musicResourceName, musicResourceType, musicExtension); | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	if (nRet) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		getMciPlayerList()[nRet]->play(repeatTimes); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	return nRet; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | UINT e2d::EMusicUtils::preloadMusic(const EString & musicFilePath) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	if (musicFilePath.isEmpty())  | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	UINT nRet = musicFilePath.hash(); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	if (getMciPlayerList().end() != getMciPlayerList().find(nRet))  | 
					
						
							|  |  |  | 		return nRet; | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	getMciPlayerList().insert(Music(nRet, new MciPlayer())); | 
					
						
							|  |  |  | 	MciPlayer * pPlayer = getMciPlayerList()[nRet]; | 
					
						
							|  |  |  | 	pPlayer->open(musicFilePath, nRet); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	if (nRet == pPlayer->getMusicID()) return nRet; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	delete pPlayer; | 
					
						
							|  |  |  | 	getMciPlayerList().erase(nRet); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | UINT e2d::EMusicUtils::preloadMusic(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	if (musicResourceName.isEmpty() || musicResourceType.isEmpty()) | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	UINT nRet = musicResourceName.hash(); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	if (getMciPlayerList().end() != getMciPlayerList().find(nRet))  | 
					
						
							|  |  |  | 		return nRet; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	getMciPlayerList().insert(Music(nRet, new MciPlayer())); | 
					
						
							|  |  |  | 	MciPlayer * pPlayer = getMciPlayerList()[nRet]; | 
					
						
							|  |  |  | 	pPlayer->open(musicResourceName, musicResourceType, musicExtension, nRet); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	if (nRet == pPlayer->getMusicID()) return nRet; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	delete pPlayer; | 
					
						
							|  |  |  | 	getMciPlayerList().erase(nRet); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | bool e2d::EMusicUtils::resumeMusic(UINT musicId) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	MusicList::iterator p = getMciPlayerList().find(musicId); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	if (p != getMciPlayerList().end()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		p->second->resume(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | bool e2d::EMusicUtils::resumeMusic(const EString & musicName) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	return resumeMusic(musicName.hash());; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | bool e2d::EMusicUtils::pauseMusic(UINT musicId) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	MusicList::iterator p = getMciPlayerList().find(musicId); | 
					
						
							|  |  |  | 	if (p != getMciPlayerList().end()) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		p->second->pause(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | bool e2d::EMusicUtils::pauseMusic(const EString & musicName) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	return pauseMusic(musicName.hash()); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | bool e2d::EMusicUtils::stopMusic(UINT musicId) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	MusicList::iterator p = getMciPlayerList().find(musicId); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	if (p != getMciPlayerList().end()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		p->second->stop(); | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  | bool e2d::EMusicUtils::stopMusic(const EString & musicName) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-11 18:17:24 +08:00
										 |  |  | 	return stopMusic(musicName.hash());; | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::EMusicUtils::pauseAllMusics() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		(*iter).second->pause(); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::EMusicUtils::resumeAllMusics() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		(*iter).second->resume(); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::EMusicUtils::stopAllMusics() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 	for (auto iter = getMciPlayerList().begin(); iter != getMciPlayerList().end(); iter++) | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  | 		(*iter).second->stop(); | 
					
						
							| 
									
										
										
										
											2017-10-25 10:54:03 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |