Permalink
Browse files

clean up resume play for stacked ISO files

  • Loading branch information...
1 parent 9080eab commit 0062d8bc6f07d3077e7d00a05734d690a9d029d8 Voyager-xbmc committed Jun 18, 2012
View
@@ -370,6 +370,7 @@ CApplication::CApplication(void)
#endif
#endif
, m_itemCurrentFile(new CFileItem)
+ , m_stackFileItemToUpdate(new CFileItem)
, m_progressTrackingVideoResumeBookmark(*new CBookmark)
, m_progressTrackingItem(new CFileItem)
, m_videoInfoScanner(new CVideoInfoScanner)
@@ -3605,26 +3606,35 @@ bool CApplication::PlayStack(const CFileItem& item, bool bRestart)
CFileItemList movieList;
dir.GetDirectory(item.GetPath(), movieList);
- int selectedFile = 1; // if playing from beginning, play file 1.
- long startoffset = item.m_lStartOffset;
+ // first assume values passed to the stack
+ int selectedFile = item.m_lStartPartNumber;
+ int startoffset = item.m_lStartOffset;
- // We instructed the stack to resume.
+ // check if we instructed the stack to resume from default
if (startoffset == STARTOFFSET_RESUME) // selected file is not specified, pick the 'last' resume point
- startoffset = CGUIWindowVideoBase::GetResumeItemOffset(&item);
-
- if (startoffset & 0xF0000000) /* selected part is specified as a flag */
{
- selectedFile = (startoffset>>28);
- startoffset = startoffset & ~0xF0000000;
-
- // set startoffset in movieitem. The remaining startoffset is either 0 (just play part from beginning) or positive (then we use STARTOFFSET_RESUME).
- if (selectedFile > 0 && selectedFile <= (int)movieList.Size())
- movieList[selectedFile - 1]->m_lStartOffset = startoffset > 0 ? STARTOFFSET_RESUME : 0;
+ if (dbs.Open())
+ {
+ CBookmark bookmark;
+ if (dbs.GetResumeBookMark(item.GetPath(), bookmark))
+ {
+ startoffset = (int)(bookmark.timeInSeconds*75);
+ selectedFile = bookmark.partNumber;
+ }
+ dbs.Close();
+ }
+ else
+ CLog::Log(LOGERROR, "%s - Cannot open VideoDatabase", __FUNCTION__);
}
- // finally play selected item
+ // set startoffset in movieitem, track stack item for updating purposes, and finally play disc part
if (selectedFile > 0 && selectedFile <= (int)movieList.Size())
+ {
+ movieList[selectedFile - 1]->m_lStartOffset = startoffset > 0 ? STARTOFFSET_RESUME : 0;
+ movieList[selectedFile - 1]->SetProperty("stackFileItemToUpdate", true);
+ *m_stackFileItemToUpdate = item;
return PlayFile(*(movieList[selectedFile - 1]));
+ }
}
// case 2: all other stacks
else
@@ -4290,6 +4300,7 @@ void CApplication::SaveFileState(bool bForeground /* = false */)
if (bForeground)
{
CSaveFileStateJob job(*m_progressTrackingItem,
+ *m_stackFileItemToUpdate,
m_progressTrackingVideoResumeBookmark,
m_progressTrackingPlayCountUpdate);
@@ -4299,6 +4310,7 @@ void CApplication::SaveFileState(bool bForeground /* = false */)
else
{
CJob* job = new CSaveFileStateJob(*m_progressTrackingItem,
+ *m_stackFileItemToUpdate,
m_progressTrackingVideoResumeBookmark,
m_progressTrackingPlayCountUpdate);
CJobManager::GetInstance().AddJob(job, NULL);
View
@@ -370,6 +370,8 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
CFileItemPtr m_itemCurrentFile;
CFileItemList* m_currentStack;
+ CFileItemPtr m_stackFileItemToUpdate;
+
CStdString m_prevMedia;
CSplash* m_splash;
ThreadIdentifier m_threadID; // application thread ID. Used in applicationMessanger to know where we are firing a thread with delay from.
View
@@ -74,6 +74,7 @@ CFileItem::CFileItem(const CSong& song)
m_strPath = song.strFileName;
GetMusicInfoTag()->SetSong(song);
m_lStartOffset = song.iStartOffset;
+ m_lStartPartNumber = 0;
SetProperty("item_start", song.iStartOffset);
m_lEndOffset = song.iEndOffset;
m_strThumbnailImage = song.strThumb;
@@ -297,6 +298,7 @@ const CFileItem& CFileItem::operator=(const CFileItem& item)
}
m_lStartOffset = item.m_lStartOffset;
+ m_lStartPartNumber = item.m_lStartPartNumber;
m_lEndOffset = item.m_lEndOffset;
m_strDVDLabel = item.m_strDVDLabel;
m_strTitle = item.m_strTitle;
@@ -333,6 +335,7 @@ void CFileItem::Reset()
m_dateTime.Reset();
m_iDriveType = CMediaSource::SOURCE_TYPE_UNKNOWN;
m_lStartOffset = 0;
+ m_lStartPartNumber = 0;
m_lEndOffset = 0;
m_iprogramCount = 0;
m_idepth = 1;
@@ -371,6 +374,7 @@ void CFileItem::Archive(CArchive& ar)
ar << m_iprogramCount;
ar << m_idepth;
ar << m_lStartOffset;
+ ar << m_lStartPartNumber;
ar << m_lEndOffset;
ar << m_iLockMode;
ar << m_strLockCode;
@@ -417,6 +421,7 @@ void CFileItem::Archive(CArchive& ar)
ar >> m_iprogramCount;
ar >> m_idepth;
ar >> m_lStartOffset;
+ ar >> m_lStartPartNumber;
ar >> m_lEndOffset;
int temp;
ar >> temp;
View
@@ -310,6 +310,7 @@ class CFileItem :
int m_iprogramCount;
int m_idepth;
int m_lStartOffset;
+ int m_lStartPartNumber;
int m_lEndOffset;
LockType m_iLockMode;
CStdString m_strLockCode;
@@ -308,7 +308,7 @@ void CGUIDialogContextMenu::GetContextButtons(const CStdString &type, const CFil
{
// We need to check if there is a detected is inserted!
buttons.Add(CONTEXT_BUTTON_PLAY_DISC, 341); // Play CD/DVD!
- if (CGUIWindowVideoBase::GetResumeItemOffset(item.get()) > 0)
+ if (CGUIWindowVideoBase::HasResumeItemOffset(item.get()))
buttons.Add(CONTEXT_BUTTON_RESUME_DISC, CGUIWindowVideoBase::GetResumeString(*(item.get()))); // Resume Disc
buttons.Add(CONTEXT_BUTTON_EJECT_DISC, 13391); // Eject/Load CD/DVD!
@@ -8,13 +8,16 @@
class CSaveFileStateJob : public CJob
{
CFileItem m_item;
+ CFileItem m_item_discstack;
CBookmark m_bookmark;
bool m_updatePlayCount;
public:
CSaveFileStateJob(const CFileItem& item,
+ const CFileItem& item_discstack,
const CBookmark& bookmark,
bool updatePlayCount)
: m_item(item),
+ m_item_discstack(item_discstack),
m_bookmark(bookmark),
m_updatePlayCount(updatePlayCount) {}
virtual ~CSaveFileStateJob() {}
@@ -85,6 +88,12 @@ bool CSaveFileStateJob::DoWork()
videodatabase.SetStreamDetailsForFile(m_item.GetVideoInfoTag()->m_streamDetails,progressTrackingFile);
updateListing = true;
}
+ // in order to properly update the the list, we need to update the stack item which is held in g_application.m_stackFileItemToUpdate
+ if (m_item.HasProperty("stackFileItemToUpdate"))
+ {
+ m_item = m_item_discstack; // as of now, the item is replaced by the discstack item
+ videodatabase.GetResumePoint(*m_item.GetVideoInfoTag());
+ }
videodatabase.Close();
if (updateListing)
View
@@ -32,6 +32,7 @@ void CBookmark::Reset()
seasonNumber = 0;
timeInSeconds = 0.0f;
totalTimeInSeconds = 0.0f;
+ partNumber = 0;
type = STANDARD;
}
View
@@ -31,6 +31,7 @@ class CBookmark
void Reset();
double timeInSeconds;
double totalTimeInSeconds;
+ long partNumber;
CStdString thumbNailImage;
CStdString playerState;
CStdString player;
@@ -2253,10 +2253,22 @@ void CVideoDatabase::GetFilePathById(int idMovie, CStdString &filePath, VIDEODB_
}
//********************************************************************************************************************************
-void CVideoDatabase::GetBookMarksForFile(const CStdString& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type /*= CBookmark::STANDARD*/, bool bAppend)
+void CVideoDatabase::GetBookMarksForFile(const CStdString& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type /*= CBookmark::STANDARD*/, bool bAppend, long partNumber)
{
try
{
+ if (URIUtils::IsStack(strFilenameAndPath) && CFileItem(CStackDirectory::GetFirstStackedFile(strFilenameAndPath),false).IsDVDImage())
+ {
+ CStackDirectory dir;
+ CFileItemList fileList;
+ dir.GetDirectory(strFilenameAndPath, fileList);
+ if (!bAppend)
+ bookmarks.clear();
+ for (int i = fileList.Size() - 1; i >= 0; i--) // put the bookmarks of the highest part first in the list
+ GetBookMarksForFile(fileList[i]->GetPath(), bookmarks, type, true, (i+1));
+ }
+ else
+ {
int idFile = GetFileId(strFilenameAndPath);
if (idFile < 0) return ;
if (!bAppend)
@@ -2270,6 +2282,7 @@ void CVideoDatabase::GetBookMarksForFile(const CStdString& strFilenameAndPath, V
{
CBookmark bookmark;
bookmark.timeInSeconds = m_pDS->fv("timeInSeconds").get_asDouble();
+ bookmark.partNumber = partNumber;
bookmark.totalTimeInSeconds = m_pDS->fv("totalTimeInSeconds").get_asDouble();
bookmark.thumbNailImage = m_pDS->fv("thumbNailImage").get_asString();
bookmark.playerState = m_pDS->fv("playerState").get_asString();
@@ -2288,6 +2301,7 @@ void CVideoDatabase::GetBookMarksForFile(const CStdString& strFilenameAndPath, V
}
//sort(bookmarks.begin(), bookmarks.end(), SortBookmarks);
m_pDS->close();
+ }
}
catch (...)
{
@@ -2940,7 +2954,7 @@ bool CVideoDatabase::GetStreamDetails(CVideoInfoTag& tag) const
return retVal;
}
-bool CVideoDatabase::GetResumePoint(CVideoInfoTag& tag) const
+bool CVideoDatabase::GetResumePoint(CVideoInfoTag& tag)
{
if (tag.m_iFileId < 0)
return false;
@@ -2949,17 +2963,38 @@ bool CVideoDatabase::GetResumePoint(CVideoInfoTag& tag) const
try
{
+ if (URIUtils::IsStack(tag.m_strFileNameAndPath) && CFileItem(CStackDirectory::GetFirstStackedFile(tag.m_strFileNameAndPath),false).IsDVDImage())
+ {
+ CStackDirectory dir;
+ CFileItemList fileList;
+ dir.GetDirectory(tag.m_strFileNameAndPath, fileList);
+ tag.m_resumePoint.Reset();
+ for (int i = fileList.Size() - 1; i >= 0; i--)
+ {
+ CBookmark bookmark;
+ if (GetResumeBookMark(fileList[i]->GetPath(), bookmark))
+ {
+ tag.m_resumePoint = bookmark;
+ tag.m_resumePoint.partNumber = (i+1); /* store part number in here */
+ match = true;
+ break;
+ }
+ }
+ }
+ else
+ {
CStdString strSQL=PrepareSQL("select timeInSeconds, totalTimeInSeconds from bookmark where idFile=%i and type=%i order by timeInSeconds", tag.m_iFileId, CBookmark::RESUME);
m_pDS2->query( strSQL.c_str() );
if (!m_pDS2->eof())
{
tag.m_resumePoint.timeInSeconds = m_pDS2->fv(0).get_asDouble();
tag.m_resumePoint.totalTimeInSeconds = m_pDS2->fv(1).get_asDouble();
+ tag.m_resumePoint.partNumber = 0; // regular files or non-iso stacks don't need partNumber
tag.m_resumePoint.type = CBookmark::RESUME;
-
match = true;
}
m_pDS2->close();
+ }
}
catch (...)
{
@@ -463,7 +463,7 @@ class CVideoDatabase : public CDatabase
bool GetStackTimes(const CStdString &filePath, std::vector<int> &times);
void SetStackTimes(const CStdString &filePath, std::vector<int> &times);
- void GetBookMarksForFile(const CStdString& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type = CBookmark::STANDARD, bool bAppend=false);
+ void GetBookMarksForFile(const CStdString& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type = CBookmark::STANDARD, bool bAppend=false, long partNumber=0);
void AddBookMarkToFile(const CStdString& strFilenameAndPath, const CBookmark &bookmark, CBookmark::EType type = CBookmark::STANDARD);
bool GetResumeBookMark(const CStdString& strFilenameAndPath, CBookmark &bookmark);
void DeleteResumeBookMark(const CStdString &strFilenameAndPath);
@@ -472,7 +472,7 @@ class CVideoDatabase : public CDatabase
bool GetBookMarkForEpisode(const CVideoInfoTag& tag, CBookmark& bookmark);
void AddBookMarkForEpisode(const CVideoInfoTag& tag, const CBookmark& bookmark);
void DeleteBookMarkForEpisode(const CVideoInfoTag& tag);
- bool GetResumePoint(CVideoInfoTag& tag) const;
+ bool GetResumePoint(CVideoInfoTag& tag);
// scraper settings
void SetScraperForPath(const CStdString& filePath, const ADDON::ScraperPtr& info, const VIDEO::SScanSettings& settings);
Oops, something went wrong.

0 comments on commit 0062d8b

Please sign in to comment.