基本播放与程序化创建的windows媒体播放器 [英] basic playback with programmatically created windows media player

查看:219
本文介绍了基本播放与程序化创建的windows媒体播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过COM来快速集成Windows Media Player,以便从本地文件系统或http源播放单个文件 - 但由于其使用的文档和在线资源稀少当不嵌入到某种Ole容器中时,我不能得到那么简单的用例。

I was trying to "just quickly integrate" the Windows Media Player via COM to play single files from the local file system or http sources - but due to the sparse documentation and online resources to its usage when not embedding into some kind of an Ole container, i couldn't get that supposedly trivial use-case to work.

初始化等工作正常,但实际上文件总是失败。

Initialization etc. works fine, but actually playing some file always fails.

示例代码,从初始化开始(错误处理已删除,基本上从 C#示例在MSDN ,在主线程上执行):

Example code, starting with initialization (error handling stripped, basically translated from the C# example at MSDN, executed on the main thread):

CComPtr<IWMPPlayer> player;
player.CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER);
CComQIPtr<IWMPCore3> core(player);
CComPtr<IWMPControls> controls;
core->get_controls(&controls);
CComPtr<IWMPPlaylist> playlist;
core->get_currentPlaylist(&playlist);
CComBSTR path("c:\\bar.mp3"); // alternatively http://foo/bar.mp3

>command not available

The first approach to play something gives "command not available":

core->put_url(path);
// ... waiting after that for WMP to load doesn't make a difference
controls->play(); // returns 0x000D1105 - NS_S_WMPCORE_COMMAND_NOT_AVAILABLE

第二种方法只产生 S_OK s,但没有实际播放:

The second approach only produces S_OKs, but nothing is actually played:

CComPtr<IWMPMedia> media;
core->newMedia(path, &media);
playlist->appendItem(media);
controls->playItem(media); // returns S_OK, but doesn't play

我注意到的另一件事是 core-> get_playState()总是返回 wmposMediaOpening ,无论我等待多久。

Another thing i noted is that core->get_playState() always returns wmposMediaOpening, no matter how long i wait.

我偶然发现一个线程表明多线程可能无法正常工作与WMP和这个代码运行在多线程的公寓。可能是问题?

如果没有,还有什么可能阻止WMP播放文件?

I've stumbled upon one thread that suggests multi-threading might not work properly with WMP and this code runs in a multi-threaded apartment. Might that be the problem?
If not, what else could be preventing WMP from playing the files?

值得注意的背景: em>

WMP实例是在以浏览器作为主机进程的DLL中创建的。

Notable background:
The WMP instance is created in a DLL with a browser as the host-process.

更新:

尝试简单的DirectShow,WMP应该使用它本身,展示了一个更具体的问题 - 请参见问题< a>。

Update:
Trying plain DirectShow, which WMP should be using itself, exhibits a more specific problem - see the question for that.

推荐答案

进一步调查,事实证明,这实际上是VS2008的解决方案,因为VS2008s AtlSetPerUserRegistration()它总是活动 - 但应该只是为包含的COM服务器注册/注销。

After further investigation, it turned out that this was actually caused by a VS2005 workaround for VS2008s AtlSetPerUserRegistration() which was always active - but should have been only for the contained COM servers registration/unregistration.

解决方法使用 HKEY_CURRENT_USER HKEY_LOCAL_MACHINE >,这显然导致相当一些组件失败,如果他们是在进程中创建。

The workaround overrides HKEY_LOCAL_MACHINE with HKEY_CURRENT_USER, which obviously results in quite some components failing if they are created in-process.

这篇关于基本播放与程序化创建的windows媒体播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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