Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
tutorial1.cpp
Package: VC++视频传输.rar [view]
Upload User: hxb_1234
Upload Date: 2010-03-30
Package Size: 8328k
Code Size: 3k
Category:
Visual C++ Books
Development Platform:
Visual C++
- //-----------------------------------------------------------------------------
- // 文件名: play.cpp
- //
- // 描述: DirectMusic实例:显示如何在一个缺省的音频路径上播放一个片段。
- //
- //-----------------------------------------------------------------------------
- #define INITGUID
- #include <windows.h>
- #include <dmusicc.h>
- #include <dmusici.h>
- //-----------------------------------------------------------------------------
- // 定义,常量和全局变量
- //-----------------------------------------------------------------------------
- IDirectMusicLoader8* g_pLoader = NULL;
- IDirectMusicPerformance8* g_pPerformance = NULL;
- IDirectMusicSegment8* g_pSegment = NULL;
- //-----------------------------------------------------------------------------
- // 函数名: WinMain()
- // 描 述: 在一个缺省的路径上使用DirectMusic播放一个单独的WAV文件。
- //-----------------------------------------------------------------------------
- INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine,
- INT nCmdShow )
- {
- // 初始化COM
- CoInitialize(NULL);
- // 创建装载器对象
- CoCreateInstance( CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
- IID_IDirectMusicLoader8, (void**)&g_pLoader );
- // 创建演奏器对象
- CoCreateInstance( CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC,
- IID_IDirectMusicPerformance8, (void**)&g_pPerformance );
- // 用标准的音频路径初始化演奏器。
- // 这里对DirectMusic和DirectSound进行初始化,
- // 并且创建合成器。
- g_pPerformance->InitAudio( NULL, NULL, NULL,
- DMUS_APATH_SHARED_STEREOPLUSREVERB, 64,
- DMUS_AUDIOF_ALL, NULL );
- CHAR strPath[512];
- if( GetWindowsDirectory( strPath, MAX_PATH+1 ) == 0 )
- return 0;
- strcat( strPath, "\media" );
- // 告诉DirectMusic缺省的搜索路径
- WCHAR wstrSearchPath[MAX_PATH+1];
- MultiByteToWideChar( CP_ACP, 0, strPath, -1,
- wstrSearchPath, MAX_PATH );
- wstrSearchPath[MAX_PATH] = 0;
- g_pLoader->SetSearchDirectory( GUID_DirectMusicAllTypes,
- wstrSearchPath, FALSE );
- // 从文件中装载片段
- WCHAR wstrFileName[MAX_PATH] = L"ding.wav";
- if( FAILED( g_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
- IID_IDirectMusicSegment8,
- wstrFileName,
- (LPVOID*) &g_pSegment ) ) )
- {
- MessageBox( NULL, "没有发现媒体,退出采样。",
- "DirectMusic实例", MB_OK );
- g_pPerformance->CloseDown();
- g_pLoader->Release();
- g_pPerformance->Release();
- CoUninitialize();
- return 0;
- }
- // 传送片段的乐器给合成器
- g_pSegment->Download( g_pPerformance );
- // 播放缺省音频路径上的片段
- g_pPerformance->PlaySegmentEx( g_pSegment, NULL, NULL, 0,
- 0, NULL, NULL, NULL );
- // 现在DirectMusic将在背景中播放,
- // 所有继续我们的任务
- MessageBox( NULL, "点击“确定”按钮退出。", "DirectMusic实例", MB_OK );
- // 停止音乐,并关闭
- g_pPerformance->Stop( NULL, NULL, 0, 0 );
- g_pPerformance->CloseDown();
- // 清除所有接口
- g_pLoader->Release();
- g_pPerformance->Release();
- g_pSegment->Release();
- // 关闭COM
- CoUninitialize();
- return 0;
- }