如何为直接播放的声音选择特定的输出设备 [英] how to select a specific Output device for a sound played with directshow

查看:99
本文介绍了如何为直接播放的声音选择特定的输出设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我想与Directshow同时播放许多声音.但是首先,我必须为每种声音选择特定的输出设备(我有很多输出设备).
关于在播放声音之前选择设备的任何想法,谢谢.这是我程序的重要部分

hello
i want to play many sounds simultaneously with Directshow. but first, i have to select for every sound a specific output device (i have many output devices ).
any idea about selecting devices before playing sounds , thanks . this is important parts of my program

#include <windows.h>
#include <mmsystem.h>
#include <streams.h>


#include< windows.h>
#include< mmsystem.h>
#include< streams.h>

Mp3类
{
私人:
IBaseFilter * pif;
IGraphBuilder * Pigb;
IMediaControl * pimc;
IMediaEventEx * pimex;

布尔已准备就绪;

公众:
Mp3();
〜Mp3();

无效加载(LPSTR文件名);
void Cleanup();

无效Play();
无效的Pause();
无效Stop();
};


//MP3-Wav.cpp

#include"Mp3.h"


Mp3 :: Mp3()
{
pif = NULL;
Pigb = NULL;
pimc = NULL;
pimex = NULL;

准备=假;

CoInitialize(NULL);
}

Mp3 ::〜Mp3()
{
Cleanup();
}

无效的Mp3 :: Cleanup()
{
CoUninitialize();

如果(pimc)
pimc-> Stop();

if(pif)
{
pif-> Release();
pif = NULL;
}

if(pigb)
{
Pigb-> Release();
Pigb = NULL;
}

if(pimc)
{
pimc-> Release();
pimc = NULL;
}

if(pimex)
{
pimex-> Release();
pimex = NULL;
}
}

无效的Mp3 :: Load(LPSTR szFile)
{
WCHAR wFile [MAX_PATH];
MultiByteToWideChar(CP_ACP,0,szFile,-1,wFile,MAX_PATH);

如果(SUCCEEDED(CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
(void **)& this-> pigb)))
{
Pigb-> QueryInterface(IID_IMediaControl,(void **)& pimc);
Pigb-> QueryInterface(IID_IMediaEventEx,(void **)& pimex);

如果(SUCCEEDED(pigb-> RenderFile(wFile,NULL)))
{
准备好= true;
}
}
}

无效的Mp3 :: Play()
{
如果(准备就绪)
{
pimc-> Run();
}
}

无效的Mp3 :: Pause()
{
如果(准备就绪)
{
pimc-> Pause();
}
}

无效的Mp3 :: Stop()
{
如果(准备就绪)
{
pimc-> Stop();
}
}

int main()
{
MP3 classmp3;
classmp3.play()
.
.
.
}


#include <windows.h>
#include <mmsystem.h>
#include <streams.h>

class Mp3
{
private:
IBaseFilter * pif;
IGraphBuilder * pigb;
IMediaControl * pimc;
IMediaEventEx * pimex;

bool ready;

public:
Mp3();
~Mp3();

void Load(LPSTR filename);
void Cleanup();

void Play();
void Pause();
void Stop();
};


// MP3-Wav.cpp

#include "Mp3.h"


Mp3::Mp3()
{
pif = NULL;
pigb = NULL;
pimc = NULL;
pimex = NULL;

ready = false;

CoInitialize(NULL);
}

Mp3::~Mp3()
{
Cleanup();
}

void Mp3::Cleanup()
{
CoUninitialize();

if (pimc)
pimc->Stop();

if(pif)
{
pif->Release();
pif = NULL;
}

if(pigb)
{
pigb->Release();
pigb = NULL;
}

if(pimc)
{
pimc->Release();
pimc = NULL;
}

if(pimex)
{
pimex->Release();
pimex = NULL;
}
}

void Mp3::Load(LPSTR szFile)
{
WCHAR wFile[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, szFile, -1, wFile, MAX_PATH);

if (SUCCEEDED(CoCreateInstance( CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
(void **)&this->pigb)))
{
pigb->QueryInterface(IID_IMediaControl, (void **)&pimc);
pigb->QueryInterface(IID_IMediaEventEx, (void **)&pimex);

if (SUCCEEDED(pigb->RenderFile(wFile, NULL)))
{
ready = true;
}
}
}

void Mp3::Play()
{
if (ready)
{
pimc->Run();
}
}

void Mp3::Pause()
{
if (ready)
{
pimc->Pause();
}
}

void Mp3::Stop()
{
if (ready)
{
pimc->Stop();
}
}

int main ()
{
MP3 classmp3;
classmp3.play()
.
.
.
}

推荐答案

也许这是您正在寻找的函数系列?我过去肯定会使用它们进行播放和录制.

波形音频接口--->设备和数据类型 [ ^ ]
Perhaps this is the family of functions that you''re looking for? I''ve certainly used them in the past for playback and recording.

Waveform-Audio Interface--->Devices and Data Types[^]


看看这个链接 [ ^ ].

这不完全是您要的内容,但可以给您一些建议.

不管怎么说,除了在原始广告发布后的一个月内发布了几乎相同的问题一个 [ ^ ],很高兴看到您尝试自己制作...在互联网上搜索和阅读信息...并且至少您应该发布更多的信息...我不知道...代码段,您已经测试过的一些想法或类似的内容...

kinani,您应该考虑一下...提出正确的问题并正确执行是答案的一半...在这里,想要将声音广播到不同音频设备的人是您...
Take a look at this link[^].

It is not exactly what you are asking, but it could give you some advice.

Anyway... more than post an almost identical question a month after the original one[^] it would be nice to see that you''ve tried to make it by yourself... googling and reading information in the Internet... and at least you should have posted a little bit more of information... I don''t know... a code snippet, some ideas you have tested or similar...

kinani you should think about it... Asking the right question and doing it right is half the answer... and here the one that wants to broadcast sound to different audio devices is you...


这篇关于如何为直接播放的声音选择特定的输出设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆