Skip to content

Commit

Permalink
Fix some issues with saving playback position.
Browse files Browse the repository at this point in the history
  • Loading branch information
clsid2 committed Feb 12, 2022
1 parent 5ea4b31 commit 690c629
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/mpc-hc/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ bool CAppSettings::CRecentFileListWithMoreInfo::LoadMediaHistoryEntry(CStringW h
r.fns.AddTail(fn);
r.title = title;
r.cue = cue;
r.filePosition = filePosition;
r.filePosition = filePosition * 10000LL;
if (!dvdPosition.IsEmpty()) {
if (dvdPosition.GetLength() / 2 == sizeof(DVD_POSITION)) {
DeserializeHex(dvdPosition, (BYTE*)&r.DVDPosition, sizeof(DVD_POSITION));
Expand Down Expand Up @@ -3050,7 +3050,7 @@ void CAppSettings::CRecentFileListWithMoreInfo::WriteMediaHistoryEntry(RecentFil
pApp->WriteProfileString(subSection, t, strValue);
} else {
t = L"FilePosition";
pApp->WriteProfileInt(subSection, t, r.filePosition);
pApp->WriteProfileInt(subSection, t, r.filePosition / 10000LL);
persistedFilePosition = r.filePosition;
}
if (updateLastOpened) {
Expand Down
16 changes: 15 additions & 1 deletion src/mpc-hc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ void CMainFrame::OnTimer(UINT_PTR nIDEvent)
return;
}

if (m_bRememberFilePos && !m_fEndOfStream) {
if (m_bRememberFilePos && rtDur > 0LL && !m_fEndOfStream) {
auto* pMRU = &AfxGetAppSettings().MRU;
pMRU->UpdateCurrentFilePosition(rtNow);
}
Expand Down Expand Up @@ -17404,6 +17404,20 @@ void CMainFrame::CloseMedia(bool bNextIsQueued/* = false*/)
ASSERT(!m_bSettingUpMenus);
}

// save playback position
if (GetLoadState() == MLS::LOADED) {
auto& s = AfxGetAppSettings();
if (s.fKeepHistory && m_pMS) {
REFERENCE_TIME rtDur = 0;
m_pMS->GetDuration(&rtDur);
if (rtDur > 0) {
REFERENCE_TIME rtNow = 0;
m_pMS->GetCurrentPosition(&rtNow);
s.MRU.UpdateCurrentFilePosition(rtNow, true);
}
}
}

// delay showing auto-hidden controls if new media is queued
if (bNextIsQueued) {
m_controls.DelayShowNotLoaded(true);
Expand Down
8 changes: 0 additions & 8 deletions src/mpc-hc/PPagePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ BOOL CPPagePlayer::OnApply()
// Re-enable Windows recent menu and the "Recent" jump list if needed
s.fileAssoc.SetNoRecentDocs(false, true);
}
/*
if (!m_fKeepHistory || !m_fRememberFilePos) {
s.filePositions.Empty();
}
if (!m_fKeepHistory || !m_fRememberDVDPos) {
s.dvdPositions.Empty();
}
*/

// Check if the settings location needs to be changed
if (AfxGetMyApp()->IsIniValid() != !!m_fUseIni) {
Expand Down
6 changes: 2 additions & 4 deletions src/mpc-hc/PlayerPlaylistBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,10 @@ void CPlayerPlaylistBar::OnNMDblclkList(NMHDR* pNMHDR, LRESULT* pResult)

if (lpnmlv->iItem >= 0 && lpnmlv->iSubItem >= 0) {
POSITION pos = FindPos(lpnmlv->iItem);
// If the file is already playing, don't try to restore a previously saved position
if (m_pMainFrame->GetPlaybackMode() == PM_FILE && pos == m_pl.GetPos()) {
const CPlaylistItem& pli = m_pl.GetAt(pos);

// If the file is already playing, reset position
CAppSettings& s = AfxGetAppSettings();
// s.filePositions.RemoveEntry(pli.m_fns.GetHead());
s.MRU.UpdateCurrentFilePosition(0LL, true);
} else {
m_pl.SetPos(pos);
}
Expand Down

0 comments on commit 690c629

Please sign in to comment.