|
-
October 10th, 1999, 07:37 PM
#1
Playing Videos Under Windows
I would be very gratfull if somebody could help me out with this. I am trying to play a video (any format, as long that it is easy) and play it in an application...
PLEASE HELP SOMEBODY....
thankyou
-
December 22nd, 1999, 06:51 PM
#2
Re: Playing Videos Under Windows
Here is a class I wrote:
file : avi.h
// avi.h: interface for the ***O_AVI_PLAYER class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_AVI_H__21EF7694_C055_4ADC_9242_41F4A54EAD4D__INCLUDED_)
#define AFX_AVI_H__21EF7694_C055_4ADC_9242_41F4A54EAD4D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "mmsystem.h"
#include "mciavi.h"
#include "digitalv.h"
class ***O_AVI_PLAYER
{
public:
BOOL m_finished;
void OnMCI(WPARAM wParam, LPARAM lParam);
void ResetResolution();
void Close();
void SetResolution();
MCIDEVICEID m_deviceID;
void Open(char *path);
void Play();
***O_AVI_PLAYER();
virtual ~***O_AVI_PLAYER();
};
#endif // !defined(AFX_AVI_H__21EF7694_C055_4ADC_9242_41F4A54EAD4D__INCLUDED_)
File:avi.cpp
// avi.cpp: implementation of the ***O_AVI_PLAYER class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "aviplay.h"
#include "avi.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define ***O_VIDEO "avivideo"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
***O_AVI_PLAYER::***O_AVI_PLAYER()
{
m_deviceID = NULL;
m_finished = FALSE;
}
***O_AVI_PLAYER::~***O_AVI_PLAYER()
{
Close();
}
void ***O_AVI_PLAYER::Play()
{
SetResolution();
DWORD dwFlags = MCI_MCIAVI_PLAY_FULLSCREEN | MCI_NOTIFY;
MCI_DGV_PLAY_PARMS mciPlay;
memset(&mciPlay, 0, sizeof(mciPlay));
mciPlay.dwCallback = MAKELONG(AfxGetMainWnd()->m_hWnd, 0);
// Init to play all
mciPlay.dwFrom = mciPlay.dwTo = 0;
MCIERROR error = mciSendCommand(m_deviceID, MCI_PLAY, dwFlags, (DWORD)(LPMCI_DGV_PLAY_PARMS)&mciPlay);
if (error != 0)
{
char text[256];
mciGetErrorString(error, text, 256);
AfxMessageBox(text);
}
}
void ***O_AVI_PLAYER::Open(char *path)
{
MCI_DGV_OPEN_PARMS mciOpen;
memset(&mciOpen, 0, sizeof(mciOpen));
mciOpen.lpstrDeviceType = ***O_VIDEO;
mciOpen.lpstrElementName = path;
MCIERROR error = mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT | MCI_DGV_OPEN_16BIT, (DWORD) &mciOpen);
if (error != 0)
{
char text[256];
mciGetErrorString(error, text, 256);
AfxMessageBox(text);
}
m_deviceID = mciOpen.wDeviceID;
}
void ***O_AVI_PLAYER::SetResolution()
{
DEVMODE devMode;
devMode.dmSize = sizeof(devMode);
devMode.dmBitsPerPel = 15;
devMode.dmPelsHeight = 480;
devMode.dmPelsWidth = 640;
devMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
devMode.dmBitsPerPel = 16;
ChangeDisplaySettings(&devMode, CDS_FULLSCREEN);
}
}
void ***O_AVI_PLAYER::Close()
{
// Get the device ID for the opened device type and then close the device type.
MCI_GENERIC_PARMS mciClose;
MCIERROR error = mciSendCommand(m_deviceID, MCI_CLOSE, 0L, (DWORD)(LPMCI_GENERIC_PARMS) &mciClose);
ResetResolution();
m_finished = TRUE;
}
void ***O_AVI_PLAYER::ResetResolution()
{
ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
}
void ***O_AVI_PLAYER::OnMCI(WPARAM wParam, LPARAM lParam)
{
if (wParam == MCI_NOTIFY_SUCCESSFUL || wParam == MCI_NOTIFY_ABORTED || wParam == MCI_NOTIFY_FAILURE)
Close();
}
And how to use it :
BEGIN_MESSAGE_MAP(CAviplayDlg, CDialog)
//{{AFX_MSG_MAP(CAviplayDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_PLAY, OnPlay)
//}}AFX_MSG_MAP
ON_MESSAGE(MM_MCINOTIFY, OnMCI)
END_MESSAGE_MAP()
void CAviplayDlg::OnPlay()
{
m_player = new ***O_AVI_PLAYER();
m_player->Open("c:\\movie.avi");
m_player->Play();
}
LRESULT CAviplayDlg::OnMCI(WPARAM wParam, LPARAM lParam)
{
if (m_player != NULL)
{
m_player->OnMCI(wParam, lParam);
if (m_player->m_finished)
delete m_player;
m_player = NULL;
}
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|