]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidwin.cpp
Replaced <iostream.h> reference with "wx/ioswrap.h"
[wxWidgets.git] / utils / wxMMedia2 / lib / vidwin.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 // Name: vidwin.h
3 // Purpose: wxMMedia
4 // Author: Guilhem Lavaux
5 // Created: February 1998
6 // Updated:
7 // Copyright: (C) 1998, 1999, 2000 Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "vidwin.h"
13 #endif
14
15 #include "wx/wxprec.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20
21 #include "wx/stream.h"
22 #include "wx/wfstream.h"
23
24 #define WXMMEDIA_INTERNAL
25 #include <windows.h>
26 #include <mmsystem.h>
27 #include <digitalv.h>
28 #include "vidwin.h"
29
30 #ifdef __BORLANDC__
31 #pragma hdrstop
32 #endif
33
34 IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
35
36 wxVideoWindows::wxVideoWindows()
37 {
38 }
39
40 wxVideoWindows::wxVideoWindows(wxInputStream& str)
41 : wxVideoBaseDriver(str)
42 {
43 m_internal = new wxVIDWinternal;
44 m_remove_file = TRUE;
45 m_filename = wxGetTempFileName("wxvid");
46 m_paused = FALSE;
47 m_stopped = TRUE;
48
49 wxFileOutputStream temp_file(m_filename);
50 temp_file << str;
51
52 OpenFile();
53 }
54
55 wxVideoWindows::wxVideoWindows(const wxString& filename)
56 : wxVideoBaseDriver(filename)
57 {
58 m_internal = new wxVIDWinternal;
59 m_remove_file = FALSE;
60 m_filename = filename;
61 m_paused = FALSE;
62 m_stopped = TRUE;
63 OpenFile();
64 }
65
66 wxVideoWindows::~wxVideoWindows(void)
67 {
68 mciSendCommand(m_internal->m_dev_id, MCI_CLOSE, 0, 0);
69
70 if (m_internal)
71 delete m_internal;
72 }
73
74 void wxVideoWindows::OpenFile()
75 {
76 MCI_DGV_OPEN_PARMS open_struct;
77 DWORD ret;
78
79 open_struct.lpstrDeviceType = "avivideo";
80 open_struct.lpstrElementName = (LPSTR)(m_filename.mb_str());
81 open_struct.hWndParent = 0;
82
83 ret = mciSendCommand(0, MCI_OPEN,
84 MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_OPEN_TYPE|MCI_DGV_OPEN_32BIT,
85 (DWORD)(LPVOID)&open_struct);
86 m_internal->m_dev_id = open_struct.wDeviceID;
87 }
88
89 bool wxVideoWindows::Pause()
90 {
91 if (m_paused || m_stopped)
92 return TRUE;
93 m_paused = TRUE;
94 return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, 0, 0) == 0);
95 }
96
97 bool wxVideoWindows::Resume()
98 {
99 if (!m_paused || m_stopped)
100 return TRUE;
101 m_paused = FALSE;
102 return (mciSendCommand(m_internal->m_dev_id, MCI_PAUSE, 0, 0) == 0);
103 }
104
105 bool wxVideoWindows::IsPaused()
106 {
107 return m_paused;
108 }
109
110 bool wxVideoWindows::IsStopped()
111 {
112 return m_stopped;
113 }
114
115 bool wxVideoWindows::GetSize(wxSize& size) const
116 {
117 return TRUE;
118 }
119
120 bool wxVideoWindows::Resize(wxUint16 w, wxUint16 h)
121 {
122 return TRUE;
123 }
124
125 bool wxVideoWindows::IsCapable(wxVideoType v_type)
126 {
127 return (v_type == wxVIDEO_MSAVI);
128 }
129
130 bool wxVideoWindows::AttachOutput(wxWindow& output)
131 {
132 MCI_DGV_WINDOW_PARMS win_struct;
133
134 if (!wxVideoBaseDriver::AttachOutput(output))
135 return FALSE;
136
137 win_struct.hWnd = (HWND)output.GetHWND();
138 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
139 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
140 return TRUE;
141 }
142
143 void wxVideoWindows::DetachOutput()
144 {
145 MCI_DGV_WINDOW_PARMS win_struct;
146
147 wxVideoBaseDriver::DetachOutput();
148
149 win_struct.hWnd = 0;
150 mciSendCommand(m_internal->m_dev_id, MCI_WINDOW,
151 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&win_struct);
152 }
153
154 bool wxVideoWindows::Play()
155 {
156 if (!m_stopped)
157 return FALSE;
158 m_stopped = FALSE;
159 return (mciSendCommand(m_internal->m_dev_id, MCI_PLAY, 0, NULL) == 0);
160 }
161
162 bool wxVideoWindows::Stop()
163 {
164 if (m_stopped)
165 return FALSE;
166 m_stopped = TRUE;
167 return (mciSendCommand(m_internal->m_dev_id, MCI_STOP, 0, NULL) == 0);
168 }