]> git.saurik.com Git - wxWidgets.git/blob - src/msw/mediactrl.cpp
34a0a3351064555a9b293a2bae6196d4b79218f3
[wxWidgets.git] / src / msw / mediactrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/mediactrl.cpp
3 // Purpose: wxMediaCtrl MSW
4 // Author: Ryan Norton <wxprojects@comcast.net>
5 // Modified by:
6 // Created: 11/07/04
7 // RCS-ID: $Id$
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 //---------------------------------------------------------------------------
13 // Pre-wx includes
14 //---------------------------------------------------------------------------
15
16 //#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 //#pragma implementation "moviectrl.h"
18 //#endif
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/mediactrl.h"
28
29 #if wxUSE_MEDIACTRL
30
31 //###########################################################################
32 // DECLARATIONS
33 //###########################################################################
34
35 IMPLEMENT_CLASS(wxMediaCtrl, wxControl);
36 IMPLEMENT_DYNAMIC_CLASS(wxMediaEvent, wxEvent);
37 DEFINE_EVENT_TYPE(wxEVT_MEDIA_FINISHED);
38
39 //---------------------------------------------------------------------------
40 // wxMediaCtrlImpl
41 //---------------------------------------------------------------------------
42
43 class wxMediaCtrlImpl
44 {
45 public:
46 wxMediaCtrlImpl() : m_bLoaded(false)
47 { }
48
49 virtual ~wxMediaCtrlImpl()
50 { }
51
52 virtual bool Create(wxMediaCtrl* WXUNUSED(ctrl))
53 { return false; }
54
55 virtual bool Play() { return false; }
56 virtual bool Pause() { return false; }
57 virtual bool Stop() { return false; }
58
59 virtual bool Load(const wxString&) { return false; }
60 virtual bool Load(const wxURI&) { return false; }
61
62 virtual wxMediaState GetState() { return wxMEDIASTATE_STOPPED; }
63
64 virtual bool SetPosition(long) { return 0; }
65 virtual long GetPosition() { return 0; }
66 virtual long GetDuration() { return 0; }
67
68 virtual void DoMoveWindow(int, int, int, int) { }
69 virtual wxSize DoGetBestSize() const { return wxSize(0,0); }
70
71 virtual double GetPlaybackRate() { return 0; }
72 virtual bool SetPlaybackRate(double) { return false; }
73
74 virtual bool MSWWindowProc(WXUINT, WXWPARAM, WXLPARAM) { return false; }
75
76 bool IsLoaded()
77 { return m_bLoaded; }
78
79 bool m_bLoaded;
80 };
81
82 //---------------------------------------------------------------------------
83 // wxDXMediaCtrlImpl
84 //---------------------------------------------------------------------------
85
86 #if wxUSE_DIRECTSHOW
87
88 #include <dshow.h>
89
90 #define WM_GRAPHNOTIFY WM_USER+13
91
92 #ifdef __WXDEBUG__
93 #define wxDSVERIFY(x) wxASSERT( SUCCEEDED ((x)) )
94 #else
95 #define wxDSVERIFY(x) (x)
96 #endif
97
98 class wxDXMediaCtrlImpl : public wxMediaCtrlImpl
99 {
100 public:
101 wxDXMediaCtrlImpl();
102
103 virtual ~wxDXMediaCtrlImpl();
104
105 virtual bool Create(wxMediaCtrl* ctrl);
106
107 virtual bool Play();
108 virtual bool Pause();
109 virtual bool Stop();
110
111 virtual bool Load(const wxString& fileName);
112 virtual bool Load(const wxURI& location);
113
114 virtual wxMediaState GetState();
115
116 virtual bool SetPosition(long where);
117 virtual long GetPosition();
118 virtual long GetDuration();
119
120 virtual void DoMoveWindow(int x, int y, int w, int h);
121 wxSize DoGetBestSize() const;
122
123 virtual double GetPlaybackRate();
124 virtual bool SetPlaybackRate(double);
125
126 void Cleanup();
127
128 bool m_bVideo;
129
130 bool MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
131
132 wxMediaCtrl* m_ctrl;
133
134 IGraphBuilder* m_pGB;
135 IMediaControl* m_pMC;
136 IMediaEventEx* m_pME;
137 IVideoWindow* m_pVW;
138 IBasicAudio* m_pBA;
139 IBasicVideo* m_pBV;
140 IMediaSeeking* m_pMS;
141
142 wxSize m_bestSize;
143 };
144
145 #endif //wxUSE_DIRECTSHOW
146
147 //---------------------------------------------------------------------------
148 // wxWMMEMediaCtrlImpl
149 //---------------------------------------------------------------------------
150
151 #include <mmsystem.h>
152 #include <digitalv.h>
153
154 class wxWMMEMediaCtrlImpl : public wxMediaCtrlImpl
155 {
156 public:
157
158 wxWMMEMediaCtrlImpl();
159 ~wxWMMEMediaCtrlImpl();
160
161 virtual bool Create(wxMediaCtrl* ctrl);
162
163 virtual bool Play();
164 virtual bool Pause();
165 virtual bool Stop();
166
167 virtual bool Load(const wxString& fileName);
168 virtual bool Load(const wxURI& location);
169
170 virtual wxMediaState GetState();
171
172 virtual bool SetPosition(long where);
173 virtual long GetPosition();
174 virtual long GetDuration();
175
176 virtual void DoMoveWindow(int x, int y, int w, int h);
177 wxSize DoGetBestSize() const;
178
179 virtual double GetPlaybackRate();
180 virtual bool SetPlaybackRate(double);
181
182 MCIDEVICEID m_hDev;
183 wxMediaCtrl* m_ctrl;
184 bool m_bVideo;
185 };
186
187 //---------------------------------------------------------------------------
188 // wxAVIFileMediaCtrlImpl
189 //---------------------------------------------------------------------------
190 /*
191 #include <Vfw.h>
192 //msvfw32.dll
193 //#pragma comment(lib, "vfw32.lib")
194
195 class wxAVIFileMediaCtrlImpl : public wxMediaCtrlImpl
196 {
197 public:
198
199 wxAVIFileMediaCtrlImpl();
200 ~wxAVIFileMediaCtrlImpl();
201
202 virtual bool Create(wxMediaCtrl* ctrl);
203
204 virtual bool Play();
205 virtual bool Pause();
206 virtual bool Stop();
207
208 virtual bool Load(const wxString& fileName);
209 virtual bool Load(const wxURI& location);
210
211 virtual wxMediaState GetState();
212
213 virtual bool SetPosition(long where);
214 virtual long GetPosition();
215 virtual long GetDuration();
216
217 virtual void DoMoveWindow(int x, int y, int w, int h);
218 wxSize DoGetBestSize() const;
219
220 virtual double GetPlaybackRate();
221 virtual bool SetPlaybackRate(double);
222
223 HMODULE m_hDll;
224 PAVIFILE m_hAVIFile;
225 wxMediaCtrl* m_ctrl;
226 };
227 */
228
229 //###########################################################################
230 //
231 // IMPLEMENTATION
232 //
233 //###########################################################################
234
235 //---------------------------------------------------------------------------
236 //
237 // wxMediaCtrl
238 //
239 //---------------------------------------------------------------------------
240
241 bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, const wxString& fileName,
242 const wxPoint& pos, const wxSize& size,
243 long style, long WXUNUSED(driver), const wxString& name)
244 {
245 //base create
246 if ( !wxControl::Create(parent, id, pos, size, (style | wxNO_BORDER) | wxCLIP_CHILDREN,
247 wxDefaultValidator, name) )
248 return false;
249
250 //Set our background color to black by default
251 SetBackgroundColour(*wxBLACK);
252
253 #if wxUSE_DIRECTSHOW
254 m_imp = new wxDXMediaCtrlImpl;
255 if(!m_imp->Create(this))
256 {
257 delete m_imp;
258 #endif
259 // m_imp = new wxWMMEMediaCtrlImpl;
260 // if(!m_imp->Create(this))
261 {
262 // delete m_imp;
263 m_imp = NULL;
264 return false;
265 }
266 #if wxUSE_DIRECTSHOW
267 }
268 #endif
269
270 if(!fileName.empty())
271 {
272 if (!Load(fileName))
273 return false;
274 }
275
276 return true;
277 }
278
279 bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, const wxURI& location,
280 const wxPoint& pos, const wxSize& size,
281 long style, long WXUNUSED(driver), const wxString& name)
282 {
283 //base create
284 if ( !wxControl::Create(parent, id, pos, size, (style | wxNO_BORDER) | wxCLIP_CHILDREN,
285 wxDefaultValidator, name) )
286 return false;
287
288 //Set our background color to black by default
289 SetBackgroundColour(*wxBLACK);
290
291 #if wxUSE_DIRECTSHOW
292 m_imp = new wxDXMediaCtrlImpl;
293 if(!m_imp->Create(this))
294 {
295 delete m_imp;
296 #endif
297 // m_imp = new wxWMMEMediaCtrlImpl;
298 // if(!m_imp->Create(this))
299 {
300 // delete m_imp;
301 m_imp = NULL;
302 return false;
303 }
304 #if wxUSE_DIRECTSHOW
305 }
306 #endif
307
308 if (!Load(location))
309 return false;
310
311 return true;
312 }
313
314 bool wxMediaCtrl::Load(const wxString& fileName)
315 {
316 if(m_imp)
317 return m_imp->Load(fileName);
318 return false;
319 }
320
321 bool wxMediaCtrl::Load(const wxURI& location)
322 {
323 if(m_imp)
324 return m_imp->Load(location);
325 return false;
326 }
327
328 bool wxMediaCtrl::Play()
329 {
330 if(m_imp && m_imp->IsLoaded())
331 return m_imp->Play();
332 return false;
333 }
334
335 bool wxMediaCtrl::Pause()
336 {
337 if(m_imp && m_imp->IsLoaded())
338 return m_imp->Pause();
339 return false;
340 }
341
342 bool wxMediaCtrl::Stop()
343 {
344 if(m_imp && m_imp->IsLoaded())
345 return m_imp->Stop();
346 return false;
347 }
348
349 double wxMediaCtrl::GetPlaybackRate()
350 {
351 if(m_imp && m_imp->IsLoaded())
352 return m_imp->GetPlaybackRate();
353 return 0;
354 }
355
356 bool wxMediaCtrl::SetPlaybackRate(double dRate)
357 {
358 if(m_imp && m_imp->IsLoaded())
359 return m_imp->SetPlaybackRate(dRate);
360 return false;
361 }
362
363 bool wxMediaCtrl::SetPosition(long where)
364 {
365 if(m_imp && m_imp->IsLoaded())
366 return m_imp->SetPosition(where);
367 return false;
368 }
369
370 long wxMediaCtrl::GetPosition()
371 {
372 if(m_imp && m_imp->IsLoaded())
373 return m_imp->GetPosition();
374 return 0;
375 }
376
377 long wxMediaCtrl::GetDuration()
378 {
379 if(m_imp && m_imp->IsLoaded())
380 return m_imp->GetDuration();
381 return 0;
382 }
383
384 wxMediaState wxMediaCtrl::GetState()
385 {
386 if(m_imp && m_imp->IsLoaded())
387 return m_imp->GetState();
388 return wxMEDIASTATE_STOPPED;
389 }
390
391 WXLRESULT wxMediaCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
392 {
393 if(m_imp && m_imp->IsLoaded() && m_imp->MSWWindowProc(nMsg, wParam, lParam) )
394 return wxControl::MSWDefWindowProc(nMsg, wParam, lParam);
395 //pass the event to our parent
396 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
397 }
398
399 wxSize wxMediaCtrl::DoGetBestSize() const
400 {
401 if(m_imp && m_imp->IsLoaded())
402 return m_imp->DoGetBestSize();
403 return wxSize(0,0);
404 }
405
406 void wxMediaCtrl::DoMoveWindow(int x, int y, int w, int h)
407 {
408 wxControl::DoMoveWindow(x,y,w,h);
409
410 if(m_imp && m_imp->IsLoaded())
411 m_imp->DoMoveWindow(x, y, w, h);
412 }
413
414 wxMediaCtrl::~wxMediaCtrl()
415 {
416 if (m_imp)
417 delete m_imp;
418 }
419
420
421 //---------------------------------------------------------------------------
422 //
423 // wxDXMediaCtrlImpl
424 //
425 //---------------------------------------------------------------------------
426
427 #if wxUSE_DIRECTSHOW
428
429 wxDXMediaCtrlImpl::wxDXMediaCtrlImpl() : m_pGB(NULL)
430 {
431 }
432
433 bool wxDXMediaCtrlImpl::Create(wxMediaCtrl* ctrl)
434 {
435 //create our filter graph
436 HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
437 IID_IGraphBuilder, (void**)&m_pGB);
438
439 //directshow not installed?
440 if ( FAILED(hr) )
441 return false;
442
443 m_ctrl = ctrl;
444
445 return true;
446 }
447
448 #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
449
450 bool wxDXMediaCtrlImpl::Load(const wxString& fileName)
451 {
452 if(m_bLoaded)
453 Cleanup();
454
455 SAFE_RELEASE(m_pGB);
456
457 CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
458 IID_IGraphBuilder, (void**)&m_pGB);
459
460 //load the graph & render
461 if( FAILED(m_pGB->RenderFile(fileName.wc_str(wxConvLocal), NULL)) )
462 return false;
463
464 //get the interfaces, all of them
465 wxDSVERIFY( m_pGB->QueryInterface(IID_IMediaControl, (void**)&m_pMC) );
466 wxDSVERIFY( m_pGB->QueryInterface(IID_IMediaEventEx, (void**)&m_pME) );
467 wxDSVERIFY( m_pGB->QueryInterface(IID_IMediaSeeking, (void**)&m_pMS) );
468 wxDSVERIFY( m_pGB->QueryInterface(IID_IVideoWindow, (void**)&m_pVW) );
469 wxDSVERIFY( m_pGB->QueryInterface(IID_IBasicAudio, (void**)&m_pBA) );
470 wxDSVERIFY( m_pGB->QueryInterface(IID_IBasicVideo, (void**)&m_pBV) );
471
472 //long lVolume;
473 //pBA->get_Volume(&lVolume);
474 //E_NOTIMPL
475
476 //get the _actual_ size of the movie & remember it
477 long nX, nY, nSX, nSY;
478 if (FAILED(m_pVW->GetWindowPosition(&nX,&nY,&nSX,&nSY)))
479 {
480 m_bVideo = false;
481
482 nSX = nSY = 0;
483 }
484 else
485 {
486 m_bVideo = true;
487 }
488
489 m_bestSize.x = nSX;
490 m_bestSize.y = nSY;
491
492 if (m_bVideo)
493 {
494 wxDSVERIFY( m_pVW->put_Owner((OAHWND)m_ctrl->GetHandle()) );
495 wxDSVERIFY( m_pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS) );
496 wxDSVERIFY( m_pVW->put_Visible(OATRUE) ); //OATRUE == -1
497 }
498
499 //make it so that wxEVT_MOVIE_FINISHED works
500 wxDSVERIFY( m_pME->SetNotifyWindow((OAHWND)m_ctrl->GetHandle(), WM_GRAPHNOTIFY, 0) );
501
502 //set the time format
503 wxDSVERIFY( m_pMS->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME) );
504
505 //so that DoGetBestSize will work :)
506 m_bLoaded = true;
507
508 //work around refresh issues
509 m_ctrl->InvalidateBestSize();
510 m_ctrl->GetParent()->Layout();
511 m_ctrl->GetParent()->Refresh();
512 m_ctrl->GetParent()->Update();
513
514 return true;
515 }
516
517 bool wxDXMediaCtrlImpl::Load(const wxURI& location)
518 {
519 return Load(location.BuildUnescapedURI());
520 }
521
522 bool wxDXMediaCtrlImpl::Play()
523 {
524 return SUCCEEDED( m_pMC->Run() );
525 }
526
527 bool wxDXMediaCtrlImpl::Pause()
528 {
529 return SUCCEEDED( m_pMC->Pause() );
530 }
531
532 bool wxDXMediaCtrlImpl::Stop()
533 {
534 bool bOK = SUCCEEDED( m_pMC->Stop() );
535
536 //We don't care if it can't get to the beginning in directshow -
537 //it could be a non-seeking filter (wince midi) in which case playing
538 //starts all over again
539 SetPosition(0);
540 return bOK;
541 }
542
543 bool wxDXMediaCtrlImpl::SetPosition(long where)
544 {
545 //DS uses 100 nanos - so we need a 10 mult
546 LONGLONG pos = ((LONGLONG)where) * 10000;
547
548 return SUCCEEDED( m_pMS->SetPositions(
549 &pos,
550 AM_SEEKING_AbsolutePositioning,
551 NULL,
552 AM_SEEKING_NoPositioning
553 ) );
554 }
555
556 long wxDXMediaCtrlImpl::GetPosition()
557 {
558 LONGLONG outCur, outStop;
559 wxDSVERIFY( m_pMS->GetPositions(&outCur, &outStop) );
560
561 //h,m,s,milli - outdur is in 100 nanos
562 return outCur/10000;
563 }
564
565 long wxDXMediaCtrlImpl::GetDuration()
566 {
567 LONGLONG outDuration;
568 wxDSVERIFY( m_pMS->GetDuration(&outDuration) );
569
570 //h,m,s,milli - outdur is in 100 nanos
571 return outDuration/10000;
572 }
573
574 wxMediaState wxDXMediaCtrlImpl::GetState()
575 {
576 //TODO: MS recommends against INFINITE here - do it in stages
577 HRESULT hr;
578 OAFilterState theState;
579 hr = m_pMC->GetState(INFINITE, &theState);
580
581 wxASSERT( SUCCEEDED(hr) );
582
583 //MSW state is the same as ours
584 //State_Stopped = 0,
585 //State_Paused = State_Stopped + 1,
586 //State_Running = State_Paused + 1
587
588 return (wxMediaState) theState;
589 }
590
591 double wxDXMediaCtrlImpl::GetPlaybackRate()
592 {
593 double dRate;
594 wxDSVERIFY( m_pMS->GetRate(&dRate) );
595 return dRate;
596 }
597
598 bool wxDXMediaCtrlImpl::SetPlaybackRate(double dRate)
599 {
600 return SUCCEEDED( m_pMS->SetRate(dRate) );
601 }
602
603 bool wxDXMediaCtrlImpl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
604 {
605 if (nMsg == WM_GRAPHNOTIFY)
606 {
607 LONG evCode, evParam1, evParam2;
608 HRESULT hr=S_OK;
609
610 // Process all queued events
611 while(SUCCEEDED(m_pME->GetEvent(&evCode, (LONG_PTR *) &evParam1,
612 (LONG_PTR *) &evParam2, 0)
613 )
614 )
615 {
616 // Free memory associated with callback, since we're not using it
617 hr = m_pME->FreeEventParams(evCode, evParam1, evParam2);
618
619 // If this is the end of the clip, notify handler
620 if(EC_COMPLETE == evCode)
621 {
622 //Interestingly enough, DirectShow does not actually stop
623 //the filters - even when it reaches the end!
624 #ifdef __WXDEBUG__
625 wxASSERT( Stop() );
626 #else
627 Stop();
628 #endif
629
630 wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED, m_ctrl->GetId());
631 m_ctrl->GetParent()->ProcessEvent(theEvent);
632 }
633 }
634 return true;
635 }
636 return false;
637 }
638
639 void wxDXMediaCtrlImpl::Cleanup()
640 {
641 // Hide then disown the window
642 if(m_pVW)
643 {
644 m_pVW->put_Visible(OAFALSE); //OSFALSE == 0
645 m_pVW->put_Owner(NULL);
646 }
647
648 // Release and zero DirectShow interfaces
649 SAFE_RELEASE(m_pME);
650 SAFE_RELEASE(m_pMS);
651 SAFE_RELEASE(m_pMC);
652 SAFE_RELEASE(m_pBA);
653 SAFE_RELEASE(m_pBV);
654 SAFE_RELEASE(m_pVW);
655 }
656
657 wxDXMediaCtrlImpl::~wxDXMediaCtrlImpl()
658 {
659 if (m_bLoaded)
660 Cleanup();
661
662 SAFE_RELEASE(m_pGB);
663 }
664
665 wxSize wxDXMediaCtrlImpl::DoGetBestSize() const
666 {
667 return m_bestSize;
668 }
669
670 void wxDXMediaCtrlImpl::DoMoveWindow(int x, int y, int w, int h)
671 {
672 if(m_bLoaded && m_bVideo)
673 {
674 wxDSVERIFY( m_pVW->SetWindowPosition(0, 0, w, h) );
675 }
676 }
677
678 #endif //wxUSE_DIRECTSHOW
679
680 //---------------------------------------------------------------------------
681 //
682 // wxWMMEMediaCtrlImpl
683 //
684 //---------------------------------------------------------------------------
685
686 wxWMMEMediaCtrlImpl::wxWMMEMediaCtrlImpl() : m_bVideo(false)
687 {
688
689 }
690
691 wxWMMEMediaCtrlImpl::~wxWMMEMediaCtrlImpl()
692 {
693 mciSendCommand(m_hDev, MCI_CLOSE, 0, 0);
694 }
695
696 bool wxWMMEMediaCtrlImpl::Create(wxMediaCtrl* ctrl)
697 {
698 m_ctrl = ctrl;
699 return true;
700 }
701
702 bool wxWMMEMediaCtrlImpl::Play()
703 {
704 return (mciSendCommand(m_hDev, MCI_PLAY, 0, 0) == 0) ||
705 (mciSendCommand(m_hDev, MCI_RESUME, 0, 0) == 0);
706 }
707
708 bool wxWMMEMediaCtrlImpl::Pause()
709 {
710 return (mciSendCommand(m_hDev, MCI_PAUSE, MCI_WAIT, 0) == 0);
711 }
712
713 bool wxWMMEMediaCtrlImpl::Stop()
714 {
715 return (mciSendCommand(m_hDev, MCI_STOP, MCI_WAIT, 0) == 0) &&
716 SetPosition(GetDuration());
717 }
718
719 #include "wx/log.h"
720
721 bool wxWMMEMediaCtrlImpl::Load(const wxString& fileName)
722 {
723 if(m_bLoaded)
724 mciSendCommand(m_hDev, MCI_CLOSE, 0, 0);
725
726 MCI_OPEN_PARMS openParms;
727 MCI_SET_PARMS setParms;
728
729 memset(&openParms, 0, sizeof(MCI_DGV_OPEN_PARMS));
730 openParms.lpstrElementName = (wxChar*) fileName.c_str();
731
732 bool bFound = false;
733
734 for(size_t i = MCI_DEVTYPE_FIRST; i <= MCI_DEVTYPE_LAST; ++i)
735 {
736 openParms.lpstrDeviceType = (LPSTR)i;
737
738 DWORD nError;
739
740 if ((nError = mciSendCommand(0, MCI_OPEN,
741 MCI_OPEN_ELEMENT|MCI_OPEN_ELEMENT|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID,
742 (DWORD)(LPVOID)&openParms)) == 0)
743 {
744 bFound = true;
745 break;
746 }
747 }
748
749 if(!bFound)
750 return false;
751
752 m_hDev = openParms.wDeviceID;
753
754
755 setParms.dwCallback = 0;
756 setParms.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
757
758 if (mciSendCommand(m_hDev, MCI_SET, MCI_SET_TIME_FORMAT,
759 (DWORD)(LPVOID)&setParms) != 0)
760 return false;
761
762
763 //TODO: Does this work?
764 /*
765 MCI_DGV_WINDOW_PARMS windowParms;
766
767 windowParms.hWnd = (HWND)m_ctrl->GetHWND();
768 m_bVideo = (mciSendCommand(m_hDev, MCI_WINDOW,
769 MCI_DGV_WINDOW_HWND, (DWORD)(LPVOID)&windowParms) == 0);
770 */
771 m_bLoaded = true;
772
773 return true;
774 }
775
776 bool wxWMMEMediaCtrlImpl::Load(const wxURI& WXUNUSED(location))
777 {
778 return false;
779 }
780
781 wxMediaState wxWMMEMediaCtrlImpl::GetState()
782 {
783 MCI_STATUS_PARMS statusParms;
784 statusParms.dwItem = MCI_STATUS_MODE;
785 mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
786 (DWORD)(LPVOID)&statusParms);
787
788 if(statusParms.dwReturn == MCI_MODE_PAUSE)
789 return wxMEDIASTATE_PAUSED;
790 else if(statusParms.dwReturn == MCI_MODE_PLAY)
791 return wxMEDIASTATE_PLAYING;
792 else
793 return wxMEDIASTATE_STOPPED;
794 }
795
796 bool wxWMMEMediaCtrlImpl::SetPosition(long where)
797 {
798 MCI_SEEK_PARMS seekParms;
799 seekParms.dwCallback = 0;
800 seekParms.dwTo = where;
801
802 bool bReplay = GetState() == wxMEDIASTATE_PLAYING;
803
804 if( mciSendCommand(m_hDev, MCI_SEEK, MCI_TO, (DWORD)(LPVOID)&seekParms) != 0)
805 return false;
806 /* TCHAR sz[5000];
807 mciGetErrorString(nError, sz, 5000);
808 wxMessageBox(wxString::Format(_T("Error:%s"), sz));
809 */
810
811 if (bReplay)
812 return Play();
813 else
814 return true;
815 }
816
817 long wxWMMEMediaCtrlImpl::GetPosition()
818 {
819 MCI_STATUS_PARMS statusParms;
820
821 statusParms.dwItem = MCI_STATUS_POSITION;
822 if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
823 (DWORD)(LPSTR)&statusParms) != 0)
824 return 0;
825
826 return statusParms.dwReturn;
827 }
828
829 long wxWMMEMediaCtrlImpl::GetDuration()
830 {
831 MCI_STATUS_PARMS statusParms;
832
833 statusParms.dwItem = MCI_STATUS_LENGTH;
834 if (mciSendCommand(m_hDev, MCI_STATUS, MCI_STATUS_ITEM,
835 (DWORD)(LPSTR)&statusParms) != 0)
836 return 0;
837
838 return statusParms.dwReturn;
839 }
840
841 void wxWMMEMediaCtrlImpl::DoMoveWindow(int, int, int, int)
842 {
843 }
844
845 wxSize wxWMMEMediaCtrlImpl::DoGetBestSize() const
846 {
847 if(m_bVideo)
848 {
849 //TODO: Does this work?
850 /*
851 MCI_DGV_RECT_PARMS rect;
852
853 mciSendCommand(m_hDev, MCI_WHERE, MCI_DGV_WHERE_SOURCE, (DWORD)(LPSTR)&rect);
854 return wxSize(rect.rc.right, rect.rc.bottom);
855 */
856 }
857 return wxSize(0,0);
858 }
859
860 double wxWMMEMediaCtrlImpl::GetPlaybackRate()
861 {
862 return 1.0;
863 }
864
865 bool wxWMMEMediaCtrlImpl::SetPlaybackRate(double)
866 {
867 return false;
868 }
869
870 //---------------------------------------------------------------------------
871 //
872 // wxAVIFileMediaCtrlImpl
873 //
874 //---------------------------------------------------------------------------
875
876 //---------------------------------------------------------------------------
877 // Functions located in msvfw32.dll
878 //---------------------------------------------------------------------------
879
880 /*
881
882 typedef void (WINAPI *LPAVIFileInit) ();
883 typedef void (WINAPI *LPAVIFileExit) ();
884
885 typedef ULONG (WINAPI *LPAVIFileOpen) (
886 PAVIFILE FAR * ppfile,
887 const wxChar* szFile,
888 UINT uMode,
889 LPCLSID lpHandler
890 );
891
892 typedef ULONG (WINAPI *LPAVIFileRelease) (PAVIFILE pfile);
893
894 wxAVIFileMediaCtrlImpl::wxAVIFileMediaCtrlImpl()
895 {
896 }
897
898 wxAVIFileMediaCtrlImpl::~wxAVIFileMediaCtrlImpl()
899 {
900 }
901
902 bool wxAVIFileMediaCtrlImpl::Create(wxMediaCtrl* ctrl)
903 {
904 m_hDll = ::LoadLibrary(_T("avifil32.dll"));
905
906 if(m_hDll == NULL)
907 return false;
908
909 LPAVIFileInit pAVIFileInit = (LPAVIFileInit) ::GetProcAddress(m_hDll, _T("AVIFileInit"));
910
911 if(!pAVIFileInit)
912 return false;
913
914 (*pAVIFileInit)();
915
916 m_ctrl = ctrl;
917 return false;
918 }
919
920
921 bool wxAVIFileMediaCtrlImpl::Load(const wxString& fileName)
922 {
923 // if( AVIFileOpen(&m_hAVIFile, fileName.c_str(), OF_SHARE_DENY_WRITE, 0L) != 0)
924 return false;
925
926 m_bLoaded = true;
927
928 return true;
929 }
930
931 bool wxAVIFileMediaCtrlImpl::Load(const wxURI& WXUNUSED(location))
932 {
933 return false;
934 }
935
936 bool wxAVIFileMediaCtrlImpl::Play()
937 {
938 return 0;
939 }
940
941 bool wxAVIFileMediaCtrlImpl::Pause()
942 {
943 return 0;
944 }
945
946 bool wxAVIFileMediaCtrlImpl::Stop()
947 {
948 return 0;
949 }
950
951 wxMediaState wxAVIFileMediaCtrlImpl::GetState()
952 {
953 return wxMEDIASTATE_STOPPED;
954 }
955
956 bool wxAVIFileMediaCtrlImpl::SetPosition(long where)
957 {
958 return 0;
959 }
960
961 long wxAVIFileMediaCtrlImpl::GetPosition()
962 {
963 return 0;
964 }
965
966 long wxAVIFileMediaCtrlImpl::GetDuration()
967 {
968 return 0;
969 }
970
971 void wxAVIFileMediaCtrlImpl::DoMoveWindow(int, int, int, int)
972 {
973 }
974
975 wxSize wxAVIFileMediaCtrlImpl::DoGetBestSize() const
976 {
977 return wxSize(0,0);
978 }
979
980 double wxAVIFileMediaCtrlImpl::GetPlaybackRate()
981 {
982 return 1.0;
983 }
984
985 bool wxAVIFileMediaCtrlImpl::SetPlaybackRate(double)
986 {
987 return false;
988 }
989
990 */
991
992 #endif //wxUSE_MEDIACTRL