use Windows Media Player Com

本文介绍了一个使用Windows Media Player COM接口实现音频播放的C++示例程序。该程序通过创建Windows Media Player实例并调用其方法来播放指定的音频文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// WMPConsole.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <atlwin.h>
#include "wmp.h"

int _tmain(int argc, _TCHAR* argv[])
{
 CoInitialize(NULL);

 HRESULT hr = S_OK;
 CComBSTR bstrVersionInfo;
 CComPtr<IWMPPlayer4>  spPlayer;

 hr = spPlayer.CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER);

 if(SUCCEEDED(hr)){
  hr = spPlayer->get_versionInfo(&bstrVersionInfo);
 }

 if(SUCCEEDED(hr)){
  COLE2T pStr(bstrVersionInfo);
  MessageBox(NULL, (LPCSTR)pStr, _T("Windows Media Player Version"),MB_OK);
 }
 
 BSTR bstrURL = A2BSTR(_T("//1.mp3"));
 hr = spPlayer->put_URL(bstrURL);
 IWMPControls *controls;
 hr = spPlayer->get_controls(&controls);
 hr = controls->play();
 char c;
 std::cin >> c;
 spPlayer.Release();
 CoUninitialize();

 return 0;
}

copy wmp.h from include directory of sdk installed. I'm not sure it is right but it works.
this example create instance of Com WindowsMedisPlayer. And it use smart point of Com with 'CComPtr<IWMPPlayer> spPlayer;'.

but this code does not work now. it can't play the song 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值