Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1220 from jmarshallnz/cleanup_resume

Cleanup resume
  • Loading branch information...
commit 6791924b4686a24b7cfa4d4518b8143bc61da80f 2 parents ba01989 + d82d1a7
jmarshallnz authored August 03, 2012
8  xbmc/Application.cpp
@@ -4012,6 +4012,14 @@ bool CApplication::PlayFile(const CFileItem& item, bool bRestart)
4012 4012
           options.starttime = bookmark.timeInSeconds;
4013 4013
           options.state = bookmark.playerState;
4014 4014
         }
  4015
+        /*
  4016
+         override with information from the actual item if available.  We do this as the VFS (eg plugins)
  4017
+         may set the resume point to override whatever XBMC has stored, yet we ignore it until now so that,
  4018
+         should the playerState be required, it is fetched from the database.
  4019
+         See the note in CGUIWindowVideoBase::ShowResumeMenu.
  4020
+         */
  4021
+        if (item.HasVideoInfoTag() && item.GetVideoInfoTag()->m_resumePoint.IsSet())
  4022
+          options.starttime = item.GetVideoInfoTag()->m_resumePoint.timeInSeconds;
4015 4023
       }
4016 4024
       else if (item.HasVideoInfoTag())
4017 4025
       {
2  xbmc/GUIInfoManager.cpp
@@ -3822,7 +3822,7 @@ bool CGUIInfoManager::GetItemInt(int &value, const CGUIListItem *item, int info)
3822 3822
   switch (info)
3823 3823
   {
3824 3824
   case LISTITEM_PERCENT_PLAYED:
3825  
-    if (item->IsFileItem() && ((const CFileItem *)item)->HasVideoInfoTag() && ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds > 0 && ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.timeInSeconds > 0)
  3825
+    if (item->IsFileItem() && ((const CFileItem *)item)->HasVideoInfoTag() && ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.IsPartWay())
3826 3826
       value = (int)(100 * ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.timeInSeconds / ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds);
3827 3827
     else
3828 3828
       value = 0;
3  xbmc/ThumbLoader.cpp
@@ -199,8 +199,7 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
199 199
   m_database->Open();
200 200
 
201 201
   // resume point
202  
-  if (pItem->HasVideoInfoTag() &&
203  
-      pItem->GetVideoInfoTag()->m_resumePoint.type != CBookmark::RESUME && pItem->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds == 0)
  202
+  if (pItem->HasVideoInfoTag() && !pItem->GetVideoInfoTag()->m_resumePoint.IsSet())
204 203
   {
205 204
     if (m_database->GetResumePoint(*pItem->GetVideoInfoTag()))
206 205
       pItem->SetInvalid();
3  xbmc/filesystem/PluginDirectory.cpp
@@ -35,6 +35,7 @@
35 35
 #include "dialogs/GUIDialogProgress.h"
36 36
 #include "settings/GUISettings.h"
37 37
 #include "FileItem.h"
  38
+#include "video/VideoInfoTag.h"
38 39
 #include "guilib/LocalizeStrings.h"
39 40
 #include "utils/log.h"
40 41
 #include "utils/TimeUtils.h"
@@ -148,6 +149,8 @@ bool CPluginDirectory::GetPluginResult(const CStdString& strPath, CFileItem &res
148 149
     resultItem.SetPath(newDir->m_fileResult->GetPath());
149 150
     resultItem.SetMimeType(newDir->m_fileResult->GetMimeType(false));
150 151
     resultItem.UpdateInfo(*newDir->m_fileResult);
  152
+    if (newDir->m_fileResult->HasVideoInfoTag() && newDir->m_fileResult->GetVideoInfoTag()->m_resumePoint.IsSet())
  153
+      resultItem.m_lStartOffset = STARTOFFSET_RESUME; // resume point set in the resume item, so force resume
151 154
   }
152 155
   delete newDir;
153 156
 
16  xbmc/interfaces/python/xbmcmodule/listitem.cpp
@@ -755,13 +755,13 @@ namespace PYXBMC
755 755
     "       You can use the above as keywords for arguments and skip certain optional arguments.\n"
756 756
     "       Once you use a keyword, all following arguments require the keyword.\n"
757 757
     "\n"
758  
-    " Some of these are treated internally by XBMC, such as the 'StartOffset' property, which is\n"
759  
-    " the offset in seconds at which to start playback of an item.  Others may be used in the skin\n"
760  
-    " to add extra information, such as 'WatchedCount' for tvshow items\n"
  758
+    " Some of these are treated internally by XBMC.\n"
  759
+    " Others may be used in the skin to add extra information, such as 'WatchedCount' for tvshow items\n"
761 760
     "\n"
762 761
     "example:\n"
763 762
     "  - self.list.getSelectedItem().setProperty('AspectRatio', '1.85 : 1')\n"
764  
-    "  - self.list.getSelectedItem().setProperty('StartOffset', '256.4')\n");
  763
+    "  - self.list.getSelectedItem().setProperty('TotalTime', '3668.4')\n"
  764
+    "  - self.list.getSelectedItem().setProperty('ResumeTime', '306.8')\n");
765 765
 
766 766
   PyObject* ListItem_SetProperty(ListItem *self, PyObject *args, PyObject *kwds)
767 767
   {
@@ -798,6 +798,10 @@ namespace PYXBMC
798 798
     { // special case for mime type - don't actually stored in a property,
799 799
       self->item->SetMimeType(uText);
800 800
     }
  801
+    else if (lowerKey.CompareNoCase("totaltime") == 0)
  802
+      self->item->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds = (float)atof(uText.c_str());
  803
+    else if (lowerKey.CompareNoCase("resumetime") == 0)
  804
+      self->item->GetVideoInfoTag()->m_resumePoint.timeInSeconds = (float)atof(uText.c_str());
801 805
     else if (lowerKey.CompareNoCase("specialsort") == 0)
802 806
     {
803 807
       if (uText == "bottom")
@@ -851,6 +855,10 @@ namespace PYXBMC
851 855
       // we store it in item.m_lStartOffset instead
852 856
       value.Format("%f", self->item->m_lStartOffset / 75.0);
853 857
     }
  858
+    else if (lowerKey.CompareNoCase("totaltime") == 0)
  859
+      value.Format("%f", self->item->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds);
  860
+    else if (lowerKey.CompareNoCase("resumetime") == 0)
  861
+      value.Format("%f", self->item->GetVideoInfoTag()->m_resumePoint.timeInSeconds);
854 862
     else
855 863
       value = self->item->GetProperty(lowerKey.ToLower()).asString();
856 864
     PyXBMCGUIUnlock();
9  xbmc/video/Bookmark.cpp
@@ -36,3 +36,12 @@ void CBookmark::Reset()
36 36
   type = STANDARD;
37 37
 }
38 38
 
  39
+bool CBookmark::IsSet() const
  40
+{
  41
+  return totalTimeInSeconds > 0.0f;
  42
+}
  43
+
  44
+bool CBookmark::IsPartWay() const
  45
+{
  46
+  return totalTimeInSeconds > 0.0f && timeInSeconds > 0.0f;
  47
+}
11  xbmc/video/Bookmark.h
@@ -29,6 +29,17 @@ class CBookmark
29 29
 public:
30 30
   CBookmark();
31 31
   void Reset();
  32
+
  33
+  /*! \brief returns true if this bookmark has been set.
  34
+   \return true if totalTimeInSeconds is positive.
  35
+   */
  36
+  bool IsSet() const;
  37
+
  38
+  /*! \brief returns true if this bookmark is part way through the video file
  39
+   \return true if both totalTimeInSeconds and timeInSeconds are positive.
  40
+   */
  41
+  bool IsPartWay() const;
  42
+
32 43
   double timeInSeconds;
33 44
   double totalTimeInSeconds;
34 45
   long partNumber;
9  xbmc/video/VideoDatabase.cpp
@@ -4130,9 +4130,12 @@ bool CVideoDatabase::GetPlayCounts(const CStdString &strPath, CFileItemList &ite
4130 4130
       if (item)
4131 4131
       {
4132 4132
         item->GetVideoInfoTag()->m_playCount = m_pDS->fv(1).get_asInt();
4133  
-        item->GetVideoInfoTag()->m_resumePoint.timeInSeconds = m_pDS->fv(2).get_asInt();
4134  
-        item->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds = m_pDS->fv(3).get_asInt();
4135  
-        item->GetVideoInfoTag()->m_resumePoint.type = CBookmark::RESUME;
  4133
+        if (!item->GetVideoInfoTag()->m_resumePoint.IsSet())
  4134
+        {
  4135
+          item->GetVideoInfoTag()->m_resumePoint.timeInSeconds = m_pDS->fv(2).get_asInt();
  4136
+          item->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds = m_pDS->fv(3).get_asInt();
  4137
+          item->GetVideoInfoTag()->m_resumePoint.type = CBookmark::RESUME;
  4138
+        }
4136 4139
       }
4137 4140
       m_pDS->next();
4138 4141
     }
1  xbmc/video/VideoDatabase.h
@@ -402,6 +402,7 @@ class CVideoDatabase : public CDatabase
402 402
   void UpdateLastPlayed(const CFileItem &item);
403 403
 
404 404
   /*! \brief Get the playcount and resume point of a list of items
  405
+   Note that if the resume point is already set on an item, it won't be overridden.
405 406
    \param path the path to fetch videos from
406 407
    \param items CFileItemList to fetch the playcounts for
407 408
    \sa GetPlayCount, SetPlayCount, IncrementPlayCount
2  xbmc/video/VideoInfoScanner.cpp
@@ -1106,7 +1106,7 @@ namespace VIDEO
1106 1106
       m_database.SetPlayCount(*pItem, movieDetails.m_playCount, movieDetails.m_lastPlayed);
1107 1107
 
1108 1108
     if ((g_advancedSettings.m_bVideoLibraryImportResumePoint || libraryImport) &&
1109  
-        movieDetails.m_resumePoint.timeInSeconds > 0.0f && movieDetails.m_resumePoint.totalTimeInSeconds > 0.0f)
  1109
+        movieDetails.m_resumePoint.IsSet())
1110 1110
       m_database.AddBookMarkToFile(pItem->GetPath(), movieDetails.m_resumePoint, CBookmark::RESUME);
1111 1111
 
1112 1112
     m_database.Close();
2  xbmc/video/VideoInfoTag.cpp
@@ -536,7 +536,7 @@ void CVideoInfoTag::ToSortable(SortItem& sortable)
536 536
   
537 537
   sortable[FieldSubtitleLanguage] = m_streamDetails.GetSubtitleLanguage();
538 538
 
539  
-  sortable[FieldInProgress] = m_resumePoint.timeInSeconds > 0 && m_resumePoint.totalTimeInSeconds > 0;
  539
+  sortable[FieldInProgress] = m_resumePoint.IsPartWay();
540 540
   sortable[FieldDateAdded] = m_dateAdded.IsValid() ? m_dateAdded.GetAsDBDateTime() : StringUtils::EmptyString;
541 541
   sortable[FieldMediaType] = DatabaseUtils::MediaTypeFromString(m_type);
542 542
 }
43  xbmc/video/windows/GUIWindowVideoBase.cpp
@@ -827,7 +827,7 @@ void CGUIWindowVideoBase::GetResumeItemOffset(const CFileItem *item, int& starto
827 827
 
828 828
   if (!item->IsNFO() && !item->IsPlayList())
829 829
   {
830  
-    if (item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_resumePoint.timeInSeconds > 0.0)
  830
+    if (item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_resumePoint.IsSet())
831 831
     {
832 832
       startoffset = (int)(item->GetVideoInfoTag()->m_resumePoint.timeInSeconds*75);
833 833
       partNumber = item->GetVideoInfoTag()->m_resumePoint.partNumber;
@@ -895,7 +895,6 @@ bool CGUIWindowVideoBase::OnFileAction(int iItem, int action)
895 895
   case SELECT_ACTION_CHOOSE:
896 896
     {
897 897
       CContextButtons choices;
898  
-      bool resume = false;
899 898
 
900 899
       if (item->IsVideoDb())
901 900
       {
@@ -905,17 +904,13 @@ bool CGUIWindowVideoBase::OnFileAction(int iItem, int action)
905 904
           choices.Add(SELECT_ACTION_PLAYPART, 20324); // Play Part
906 905
       }
907 906
 
908  
-      if (!item->IsLiveTV())
  907
+      CStdString resumeString = GetResumeString(*item);
  908
+      if (!resumeString.IsEmpty())
909 909
       {
910  
-        CStdString resumeString = GetResumeString(*item);
911  
-        if (!resumeString.IsEmpty()) 
912  
-        {
913  
-          resume = true;
914  
-          choices.Add(SELECT_ACTION_RESUME, resumeString);
915  
-          choices.Add(SELECT_ACTION_PLAY, 12021);   // Start from beginning
916  
-        }
  910
+        choices.Add(SELECT_ACTION_RESUME, resumeString);
  911
+        choices.Add(SELECT_ACTION_PLAY, 12021);   // Start from beginning
917 912
       }
918  
-      if (!resume)
  913
+      else
919 914
         choices.Add(SELECT_ACTION_PLAY, 208);   // Play
920 915
 
921 916
       choices.Add(SELECT_ACTION_INFO, 22081); // Info
@@ -1003,28 +998,20 @@ void CGUIWindowVideoBase::OnRestartItem(int iItem)
1003 998
   CGUIMediaWindow::OnClick(iItem);
1004 999
 }
1005 1000
 
1006  
-CStdString CGUIWindowVideoBase::GetResumeString(CFileItem item) 
  1001
+CStdString CGUIWindowVideoBase::GetResumeString(const CFileItem &item)
1007 1002
 {
1008 1003
   CStdString resumeString;
1009  
-  CStdString partString;
1010  
-  CVideoDatabase db;
1011  
-  if (db.Open())
  1004
+  int startOffset = 0, startPart = 0;
  1005
+  GetResumeItemOffset(&item, startOffset, startPart);
  1006
+  if (startOffset > 0)
1012 1007
   {
1013  
-    CBookmark bookmark;
1014  
-    CStdString itemPath(item.GetPath());
1015  
-    if (item.IsVideoDb() || item.IsDVD())
1016  
-      itemPath = item.GetVideoInfoTag()->m_strFileNameAndPath;
1017  
-
1018  
-    if (db.GetResumeBookMark(itemPath, bookmark))
  1008
+    resumeString.Format(g_localizeStrings.Get(12022).c_str(), StringUtils::SecondsToTimeString(startOffset/75).c_str());
  1009
+    if (startPart > 0)
1019 1010
     {
1020  
-      resumeString.Format(g_localizeStrings.Get(12022).c_str(), StringUtils::SecondsToTimeString(lrint(bookmark.timeInSeconds)).c_str());
1021  
-      if (bookmark.partNumber > 0)
1022  
-      {
1023  
-        partString.Format(g_localizeStrings.Get(23051).c_str(), bookmark.partNumber);
1024  
-        resumeString.append(" (").append(partString).append(")");
1025  
-      }
  1011
+      CStdString partString;
  1012
+      partString.Format(g_localizeStrings.Get(23051).c_str(), startPart);
  1013
+      resumeString += " (" + partString + ")";
1026 1014
     }
1027  
-    db.Close();
1028 1015
   }
1029 1016
   return resumeString;
1030 1017
 }
7  xbmc/video/windows/GUIWindowVideoBase.h
@@ -50,7 +50,10 @@ class CGUIWindowVideoBase : public CGUIMediaWindow, public IBackgroundLoaderObse
50 50
 
51 51
 
52 52
   /*! \brief Show the resume menu for this item (if it has a resume bookmark)
53  
-   If a resume bookmark is found, we set the item's m_lStartOffset to STARTOFFSET_RESUME
  53
+   If a resume bookmark is found, we set the item's m_lStartOffset to STARTOFFSET_RESUME.
  54
+   Note that we do this in favour of setting the resume point, as we need additional
  55
+   information from the database (in particular, the playerState) when resuming some items
  56
+   (eg ISO/VIDEO_TS).
54 57
    \param item item to check for a resume bookmark
55 58
    \return true if an option was chosen, false if the resume menu was cancelled.
56 59
    */
@@ -77,7 +80,7 @@ class CGUIWindowVideoBase : public CGUIMediaWindow, public IBackgroundLoaderObse
77 80
    \param item selected item
78 81
    \return string containing the resume position or an empty string if there is no resume position
79 82
    */
80  
-  static CStdString GetResumeString(CFileItem item);
  83
+  static CStdString GetResumeString(const CFileItem &item);
81 84
 
82 85
 protected:
83 86
   void OnScan(const CStdString& strPath, bool scanAll = false);

0 notes on commit 6791924

Please sign in to comment.
Something went wrong with that request. Please try again.