00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Downloads_VideoPreview.h"
00009 #include "fsDownloadsMgr.h"
00010 #include "fsDirectXVersion.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 CDownloads_VideoPreview::CDownloads_VideoPreview()
00019 {
00020 m_hFile = INVALID_HANDLE_VALUE;
00021 m_vidman.m_parent = this;
00022 m_pActiveDownload = NULL;
00023 m_dwDXVersion = 0;
00024 m_bUsingVideo2 = FALSE;
00025 }
00026
00027 CDownloads_VideoPreview::~CDownloads_VideoPreview()
00028 {
00029
00030 }
00031
00032 BEGIN_MESSAGE_MAP(CDownloads_VideoPreview, CWnd)
00033
00034 ON_WM_CREATE()
00035 ON_WM_SIZE()
00036 ON_WM_ERASEBKGND()
00037 ON_MESSAGE (WM_VIDEONOTIFY, OnGraphMessage)
00038
00039 END_MESSAGE_MAP()
00040
00041 void CDownloads_VideoPreview::Set_ActiveDownload(vmsDownloadSmartPtr dld)
00042 {
00043 if (m_pActiveDownload != dld)
00044 {
00045 Stop ();
00046 m_pActiveDownload = dld;
00047 m_vidman.Update ();
00048 }
00049 }
00050
00051 BOOL CDownloads_VideoPreview::Create(CWnd *pWndParent)
00052 {
00053 CRect rc (0, 0, 50, 50);
00054
00055 if (FALSE == CWnd::Create (AfxRegisterWndClass (0, LoadCursor (NULL, IDC_ARROW), (HBRUSH) (COLOR_WINDOW+1), NULL) ,
00056 NULL, WS_CHILD, rc, pWndParent, 0x121a))
00057 return FALSE;
00058
00059 return TRUE;
00060 }
00061
00062 int CDownloads_VideoPreview::OnCreate(LPCREATESTRUCT lpCreateStruct)
00063 {
00064 if (CWnd::OnCreate(lpCreateStruct) == -1)
00065 return -1;
00066
00067 if (FALSE == m_wndVideo.Create (this))
00068 return -1;
00069
00070 m_vidman.Create (IDD_VIDMAN, this);
00071 m_vidman.ShowWindow (SW_SHOW);
00072
00073 m_vidseek.Create (IDD_VIDSEEK, this);
00074 m_vidseek.ShowWindow (SW_SHOW);
00075
00076 m_vidseek.m_hWndDuration = m_vidman.GetDlgItem (IDC__DURATIONVAL)->m_hWnd;
00077
00078 return 0;
00079 }
00080
00081 void CDownloads_VideoPreview::OnSize(UINT nType, int cx, int cy)
00082 {
00083 CWnd::OnSize(nType, cx, cy);
00084
00085 if (cx == 0 || cy == 0)
00086 return;
00087
00088 RECT rc;
00089 m_vidman.GetClientRect (&rc);
00090
00091 int cx_vidman = rc.right;
00092
00093 m_vidseek.GetClientRect (&rc);
00094
00095 int cy_vidseek = rc.bottom;
00096
00097 m_wndVideo.MoveWindow (2, 2, cx - cx_vidman, cy - cy_vidseek);
00098 if (m_bUsingVideo2)
00099 m_wndVideo2.MoveWindow (2, 2, cx - cx_vidman, cy - cy_vidseek);
00100 m_vidman.MoveWindow (cx - cx_vidman, 2, cx_vidman, cy);
00101 m_vidseek.MoveWindow (2, cy - cy_vidseek, cx - cx_vidman, cy_vidseek);
00102 }
00103
00104 BOOL CDownloads_VideoPreview::OnEraseBkgnd(CDC* pDC)
00105 {
00106 if (m_wndVideo.m_player.Get_State () != VFPS_CLOSED)
00107 {
00108 CRect rc;
00109
00110 m_wndVideo.GetWindowRect(&rc);
00111 ScreenToClient(&rc);
00112
00113 pDC->ExcludeClipRect(&rc);
00114 }
00115
00116 return CWnd::OnEraseBkgnd(pDC);
00117 }
00118
00119 LRESULT CDownloads_VideoPreview::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00120 {
00121 m_wndVideo.m_player.NotifyOwnerMessage (m_hWnd, message, wParam, lParam);
00122 return CWnd::WindowProc(message, wParam, lParam);
00123 }
00124
00125 void CDownloads_VideoPreview::Stop()
00126 {
00127 if (m_bUsingVideo2 == FALSE)
00128 {
00129 m_vidseek.Set_MediaSeeking (NULL);
00130 m_wndVideo.m_player.Close ();
00131 }
00132 else
00133 {
00134 m_bUsingVideo2 = FALSE;
00135 m_wndVideo2.DestroyWindow ();
00136 m_wndVideo.ShowWindow (SW_SHOW);
00137 }
00138 m_vidman.Update ();
00139 CloseFile ();
00140 }
00141
00142 void CDownloads_VideoPreview::Pause()
00143 {
00144 m_wndVideo.m_player.Pause ();
00145 m_vidman.Update ();
00146 }
00147
00148 vmsDownloadSmartPtr CDownloads_VideoPreview::Get_ActiveDownload()
00149 {
00150 return m_pActiveDownload;
00151 }
00152
00153 void CDownloads_VideoPreview::Play()
00154 {
00155 USES_CONVERSION;
00156
00157 if (m_bUsingVideo2)
00158 return;
00159
00160 if (m_wndVideo.m_player.Get_State () != VFPS_CLOSED)
00161 {
00162 if (m_wndVideo.m_player.Get_State () != VFPS_RUNNING)
00163 m_wndVideo.m_player.Run ();
00164 return;
00165 }
00166
00167 if (m_pActiveDownload)
00168 {
00169 HRESULT hr = E_FAIL;
00170 BOOL bWasErrMsg = FALSE;
00171
00172
00173 if (S_FALSE == CoInitialize (NULL))
00174 CoUninitialize ();
00175
00176 if (m_pActiveDownload->pMgr->IsDone ())
00177 {
00178 hr = m_wndVideo.m_player.Open2 (m_pActiveDownload->pMgr->get_OutputFilePathName ());
00179
00180 if (FAILED (hr))
00181 {
00182 fsString strFile = m_pActiveDownload->pMgr->get_OutputFilePathName ();
00183 LPCSTR psz = strrchr (strFile, '.');
00184 if (psz++)
00185 {
00186 if (lstrcmpi (psz, "flv") == 0)
00187 {
00188 CRect rc (0,0,0,0);
00189 m_wndVideo.GetWindowRect (&rc);
00190 ScreenToClient (&rc);
00191 m_wndVideo2.Create (NULL, WS_CHILD, rc, this, 0x111a);
00192 m_wndVideo2.SetBackgroundColor (0);
00193 m_wndVideo2.LoadMovie (0, ((CFdmApp*)AfxGetApp ())->m_strAppPath + "player.swf");
00194
00195 m_wndVideo.ShowWindow (SW_HIDE);
00196 m_wndVideo2.ShowWindow (SW_SHOW);
00197 m_bUsingVideo2 = TRUE;
00198
00199 CString str;
00200 str = "<invoke name=\"loadAndPlayVideo\" returntype=\"xml\">";
00201 str += "<arguments><string>"; str += strFile;
00202 str += "</string></arguments></invoke>";
00203 m_wndVideo2.CallFunction (str);
00204
00205 hr = S_OK;
00206 }
00207 }
00208 }
00209 }
00210 else
00211 {
00212 UINT64 nAvail = Get_AvailFileSize ();
00213
00214 if (nAvail)
00215 {
00216 if (FALSE == OpenFile ())
00217 {
00218 hr = E_FAIL;
00219 bWasErrMsg = TRUE;
00220 }
00221 else
00222 hr = m_wndVideo.m_player.Open (m_hFile, nAvail);
00223
00224 if (FAILED (hr) && bWasErrMsg == FALSE)
00225 {
00226 CloseFile ();
00227 hr = m_wndVideo.m_player.Open2 (m_pActiveDownload->pMgr->get_OutputFilePathName ());
00228 }
00229 }
00230 else
00231 bWasErrMsg = TRUE;
00232 }
00233
00234 if (FAILED (hr))
00235 {
00236 CloseFile ();
00237
00238 if (bWasErrMsg == FALSE)
00239 {
00240 if (m_dwDXVersion == 0)
00241 m_dwDXVersion = fsDirectXVersion::GetCurrentVersion ();
00242
00243 if (m_dwDXVersion < 0x0800)
00244 {
00245 CString strErr = LS (L_FAILEDTOOPENFILE);
00246 strErr += "\n\n"; strErr += LS (L_NEEDDX8ORBETTER);
00247 MessageBox (strErr, LS (L_ERR), MB_ICONERROR);
00248 }
00249 else
00250 {
00251 CString strErr = LS (L_FAILEDTOOPENFILE);
00252 strErr += "\n\n"; strErr += LS (L_UNKMEDIATYPE);
00253 MessageBox (strErr, LS (L_ERR), MB_ICONERROR);
00254 }
00255 }
00256
00257 m_vidseek.Set_MediaSeeking (NULL);
00258 return;
00259 }
00260
00261 if (m_bUsingVideo2 == FALSE)
00262 {
00263 IMediaSeeking* pMS = Get_Player ()->Get_MediaSeeking ();
00264 m_vidseek.Set_MediaSeeking (pMS);
00265 if (pMS)
00266 pMS->Release ();
00267
00268 m_wndVideo.m_player.Run ();
00269 m_vidman.ApplyVolumeSettings ();
00270 }
00271 }
00272 }
00273
00274 fsPartMediaPlayer* CDownloads_VideoPreview::Get_Player()
00275 {
00276 return &m_wndVideo.m_player;
00277 }
00278
00279 LRESULT CDownloads_VideoPreview::OnGraphMessage(WPARAM, LPARAM)
00280 {
00281 Get_Player ()->HandleGraphEvent ();
00282
00283 if (Get_Player ()->Get_State () == VFPS_STOPPED)
00284 Stop ();
00285
00286 m_vidman.Update ();
00287 return 0;
00288 }
00289
00290 void CDownloads_VideoPreview::Set_Volume(long lVolume)
00291 {
00292 Get_Player ()->Set_Volume (lVolume);
00293 }
00294
00295 CString CDownloads_VideoPreview::Get_FileName()
00296 {
00297 if (m_pActiveDownload == NULL)
00298 return "";
00299
00300 char szFile [10000];
00301 *szFile = 0;
00302 CDownloads_Tasks::GetFileName (m_pActiveDownload, szFile);
00303 return szFile;
00304 }
00305
00306 UINT64 CDownloads_VideoPreview::Get_FileSize()
00307 {
00308 if (m_pActiveDownload == NULL)
00309 return 0;
00310
00311 return m_pActiveDownload->pMgr->GetLDFileSize ();
00312 }
00313
00314 UINT64 CDownloads_VideoPreview::Get_AvailFileSize()
00315 {
00316 if (m_pActiveDownload == NULL)
00317 return 0;
00318
00319 if (m_pActiveDownload->pMgr->IsDone ())
00320 return m_pActiveDownload->pMgr->GetLDFileSize ();
00321
00322 if (m_pActiveDownload->pMgr->GetNumberOfSections ())
00323 {
00324 UINT64 uRes = 0;
00325
00326
00327 if (m_pActiveDownload->pMgr->GetBtDownloadMgr () == FALSE)
00328 {
00329 BOOL bDone;
00330
00331 do
00332 {
00333 bDone = TRUE;
00334
00335 for (int i = 0; i < m_pActiveDownload->pMgr->GetNumberOfSections (); i++)
00336 {
00337 vmsSectionInfo sect;
00338 m_pActiveDownload->pMgr->GetSectionInfo (i, §, TRUE);
00339
00340 if (uRes == sect.uDStart)
00341 {
00342 uRes = sect.uDCurrent;
00343 bDone = sect.uDCurrent != sect.uDEnd || sect.uDEnd == 0;
00344 break;
00345 }
00346 }
00347 }
00348 while (bDone == FALSE);
00349 }
00350 else
00351 {
00352 uRes = m_pActiveDownload->pMgr->GetBtDownloadMgr ()->get_SplittedByteCountAtBeginningOfFile ();
00353 }
00354
00355 return uRes;
00356 }
00357
00358 return 0;
00359 }
00360
00361 CString CDownloads_VideoPreview::GetDuration()
00362 {
00363 return m_vidseek.GetDuration ();
00364 }
00365
00366 void CDownloads_VideoPreview::UpdateCommand(UINT nID, BOOL *pbEnabled, BOOL *pbChecked)
00367 {
00368 m_vidman.UpdateCommand (nID, pbEnabled, pbChecked);
00369 }
00370
00371 void CDownloads_VideoPreview::SaveState()
00372 {
00373 m_vidman.SaveSettings ();
00374 }
00375
00376 BOOL CDownloads_VideoPreview::OpenFile()
00377 {
00378 CloseFile ();
00379
00380 fsString strFile = m_pActiveDownload->pMgr->get_OutputFilePathName ();
00381
00382 m_hFile = CreateFile (strFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
00383 NULL, OPEN_EXISTING, 0, NULL);
00384
00385 if (m_hFile == INVALID_HANDLE_VALUE)
00386 {
00387 char szErr [10000];
00388 fsErrorToStr (szErr, 10000, NULL);
00389 CString strErr = LS (L_FAILEDTOOPENFILE);
00390 strErr += "\n\n"; strErr += szErr;
00391 MessageBox (strErr, LS (L_ERR), MB_ICONERROR);
00392 return FALSE;
00393 }
00394
00395 return TRUE;
00396 }
00397
00398 void CDownloads_VideoPreview::CloseFile()
00399 {
00400 if (m_hFile != INVALID_HANDLE_VALUE)
00401 {
00402 CloseHandle (m_hFile);
00403 m_hFile = INVALID_HANDLE_VALUE;
00404 }
00405 }
00406
00407 void CDownloads_VideoPreview::ApplyLanguage()
00408 {
00409 m_vidman.ApplyLanguage ();
00410 }
00411
00412 void CDownloads_VideoPreview::Convert()
00413 {
00414 m_vidman.Convert ();
00415 }
00416
00417 void CDownloads_VideoPreview::set_InFVDownloads(BOOL b)
00418 {
00419 m_vidman.m_bInFVDownloads = b;
00420 }
00421
00422 BOOL CDownloads_VideoPreview::IsPlaying()
00423 {
00424 return m_bUsingVideo2 || Get_Player ()->Get_State () == VFPS_RUNNING;
00425 }
00426
00427 BOOL CDownloads_VideoPreview::IsPauseAvail()
00428 {
00429 return !m_bUsingVideo2;
00430 }
00431
00432 BOOL CDownloads_VideoPreview::IsPaused()
00433 {
00434 if (m_bUsingVideo2)
00435 return FALSE;
00436 return Get_Player ()->Get_State () == VFPS_PAUSED;
00437 }
00438
00439 BOOL CDownloads_VideoPreview::IsMuteAvail()
00440 {
00441 return !m_bUsingVideo2;
00442 }