如何在mfc对话框应用程序中嵌入媒体播放器并播放文件。 [英] How to embed media player in mfc dialog app and play files.

查看:102
本文介绍了如何在mfc对话框应用程序中嵌入媒体播放器并播放文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我一直在尝试将媒体播放器添加到我的mfc对话框并调用相同的播放URL。我没有成功。

操作系统 - Windows 10

VS工作室 - VS 2013专业版



我的目标是将媒体播放器嵌入我的应用程序并传递文件名以开始播放。



添加媒体播放器的步骤。

<小>

1.创建一个启用了activex控件的mfc应用程序对话框项目。

项目创建以下文件

video .cpp

videoDlg.cpp

video.h

videoDlg.h



2.转到资源经理

转到video.rc - Dialog

双击IDD_VIDEO_DIALOG



3右键单击并在对话框窗口中插入activex控件。

从列表中选择windows media player并按OK。



4。右键单击对话框上的媒体播放器,然后单击

类向导 - >从类型lib中选择mfc类(只有这样才能选择windows media player

从可用的库中选择windows media player< 1.0>

然后选择ImediaPlayer2 从接口中将它添加到生成的类中。

上面的步骤创建了以下

CMediaPlayer2类和CMediaPlayer.h头文件。

然后我添加类型为COcx1的变量名称vidctrl

这会创建两个文件ocx1.h和ocx1.cpp



我添加vidctrl.open ()在我的初始化代码中。它没有找到open函数。

所以我将函数从CMediaPlayer2.h复制到ocx1.h



然后我尝试再次调用vidctrl.open()并构建它。

当我运行它时会弹出一个消息窗口,说找不到成员

当我一步一步我发现当调用vidctrl.open()时弹出消息窗口。





我可以将项目文件作为拉链结束。

我面临的问题是如何将变量连接到接口函数?

任何帮助都将非常感谢。

谢谢&此致,

Rakesh

Hello
I have been trying to add media player to my mfc dialog and invoke the same to play URL. I have been unsuccessful.
OS - Windows 10
VS Studio - VS 2013 professional

My objective is to embed the media player in my application and pass a file name to to start playing.

Steps done to add media player.

1. Create a mfc application dialog project with activex control enabled.
The project creates the following files
video.cpp
videoDlg.cpp
video.h
videoDlg.h

2. Go to resource manager
Go to video.rc - Dialog
Double click IDD_VIDEO_DIALOG

3. Right click and insert activex control on the dialog window.
Choose the windows media player from the list and press OK.

4. Right click on the media player on the dialog and click
class wizard -> Choose mfc class from type lib (Only this gives windows media player as an option
From the available libraries choose "windows media player <1.0>
Then choose "ImediaPlayer2" from the interfaces and add it to generated classes.
The above step creates the following
CMediaPlayer2 class and CMediaPlayer.h header file.
Then I add variable name vidctrl of type COcx1
This creates two files ocx1.h and ocx1.cpp

The I add vidctrl.open() in my init code. It doesnt find the open function.
So I copy the functions from the CMediaPlayer2.h to ocx1.h

Then I try to call vidctrl.open() again and it builds.
When I run it a message window pops up saying "member not found"
When I step through I find that message window pops when the vidctrl.open() is called.


I can send the project files as a zip for this.
The problem I am facing is how to connect the variable to the interface functions?
Any help would be very much appreciated.
Thanks & Regards,
Rakesh

推荐答案

您好b $ b

以下是开始使用Media的步骤基于MFC对话框的应用程序上的播放器



1:创建基于MFC应用程序的新对话框



2:打开对话框设计器并删除由VS模板创建的默认标签控件



3:右键单击对话框并选择插入activex控件



4:选择并将Windows Media Player控件插入对话框



5:调整大小并重新定位控件



6:右键单击控制并选择添加变量



7:输入 m_MediaPlayer (或任何你想要的)作为控制变量而不更改任何其他属性



8:这将添加 ocx1.h 和项目的 ocx1.cpp ,以及 #includeocx1.h也被添加到主对话框



9:打开 stdafx.h 并添加此 #include< wmp.h> include指令



10:打开包含Media Player对象的Dialog类头文件并添加 CComPtr< IWMPPlayer> ; m_pWMPPlayer; 变量到它的某个地方



11:现在打开对话框类的CPP文件并转到OnInitDialog()并添加以下代码

Hi
Here is the steps to start working with Media Player on a MFC Dialog based application

1: Create a new dialog based MFC application

2: Open dialog designer and remove default label control that's created by VS template

3: Right click in dialog and select insert activex control

4: Select and insert Windows Media Player control to dialog

5: Resize and reposition control as you whish

6: Right click to control and select Add Variable

7: Enter m_MediaPlayer (or whatever you want) as the control variable without changing any other property

8: This will add a ocx1.h and a ocx1.cpp to the project , and #include "ocx1.h" is also added to main dialog

9: Open stdafx.h and add this #include <wmp.h> include directive to it

10: Open header file of Dialog class that contains Media Player object and add this CComPtr<IWMPPlayer> m_pWMPPlayer; variable to somewhere in it

11: Now open CPP file of dialog class and goto OnInitDialog() and add following code
LPUNKNOWN pUnknown = m_MediaPlayerControl.GetControlUnknown();
HRESULT hr = pUnknown->QueryInterface(__uuidof(IWMPPlayer), (void**)&m_pWMPPlayer);
if(SUCCEEDED(hr))
{
	CComBSTR strMovie = _T("Full Path To Movie File");
	m_pWMPPlayer->put_URL(strMovie); 
}





12:构建并查看结果





如果你想实现Media Player的更多功能,那么

看看MSDN网站上的媒体播放器的可用接口接口(Windows Media Player) [ ^ ]


我有点困惑:



我可以插入控件罚款,但是从那里开始对我不起作用。以下:



6:右键单击控制并选择添加变量



7:输入m_MediaPlayer(或任何你想要的)作为控制变量而不更改任何其他属性



8:这将为项目添加ocx1.h和ocx1.cpp ,#includeocx1.h也被添加到主对话框




目前还不清楚。



a)右键单击控件或对话框本身?

b)什么类型是m_MediaPlayer?

c)ocx1头文件和源文件没有添加到矿。



当我按照上述步骤操作时,添加到我文件中的所有内容都是COCX类型的变量m_MediaPlayer。

类型COCX随后被编译器无法识别。



请帮忙。



BW,Rez。
I am a little bit perplexed by this:

I can insert the control fine, but from there on the instructions don't work for me. The following:

6: Right click to control and select Add Variable

7: Enter m_MediaPlayer (or whatever you want) as the control variable without changing any other property

8: This will add a ocx1.h and a ocx1.cpp to the project , and #include "ocx1.h" is also added to main dialog
.

is unclear.

a) Right click on the control or the dialog itself?
b) What type is m_MediaPlayer ?
c) the ocx1 header and source files do not get added in mine.

When I follow the above steps, all that is added to my files is a variable m_MediaPlayer of type COCX.
Type COCX is subsequently unrecognised by the compiler.

Please help.

BW, Rez.


这篇关于如何在mfc对话框应用程序中嵌入媒体播放器并播放文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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