diff options
author | Dimitry Ishenko <dimitry.ishenko@gmail.com> | 2019-01-08 12:43:07 -0500 |
---|---|---|
committer | Dimitry Ishenko <dimitry.ishenko@gmail.com> | 2019-01-08 14:32:25 -0500 |
commit | 7a5a3a8aede277c6c9bf38ba0f64feea5864f9dc (patch) | |
tree | 8dcd36b18b5dd10f3019f8507449e77ea3a9a5d9 | |
parent | 4abe3490217c76d13751ebd6270e40e837bb0953 (diff) |
Misc fixes to prevent crashes when playing audio books
-rw-r--r-- | xbmc/music/MusicDatabase.cpp | 15 | ||||
-rw-r--r-- | xbmc/music/windows/GUIWindowMusicBase.cpp | 22 |
2 files changed, 26 insertions, 11 deletions
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp index 96035f7542..5e48e68f9b 100644 --- a/xbmc/music/MusicDatabase.cpp +++ b/xbmc/music/MusicDatabase.cpp @@ -10708,11 +10708,16 @@ void CMusicDatabase::UpdateFileDateAdded(int songId, const std::string& strFileN bool CMusicDatabase::AddAudioBook(const CFileItem& item) { - std::string strSQL = PrepareSQL("INSERT INTO audiobook (idBook,strBook,strAuthor,bookmark,file,dateAdded) VALUES (NULL,'%s','%s',%i,'%s','%s')", - item.GetMusicInfoTag()->GetAlbum().c_str(), - item.GetMusicInfoTag()->GetArtist()[0].c_str(), 0, - item.GetPath().c_str(), - CDateTime::GetCurrentDateTime().GetAsDBDateTime().c_str()); + auto const& artists = item.GetMusicInfoTag()->GetArtist(); + std::string strSQL = PrepareSQL( + "INSERT INTO audiobook (idBook,strBook,strAuthor,bookmark,file,dateAdded) " + "VALUES (NULL,'%s','%s',%i,'%s','%s')", + item.GetMusicInfoTag()->GetAlbum().c_str(), + artists.empty() ? "" : artists[0].c_str(), + 0, + item.GetPath().c_str(), + CDateTime::GetCurrentDateTime().GetAsDBDateTime().c_str() + ); return ExecuteQuery(strSQL); } diff --git a/xbmc/music/windows/GUIWindowMusicBase.cpp b/xbmc/music/windows/GUIWindowMusicBase.cpp index cb27b0c6a3..d0b7650c16 100644 --- a/xbmc/music/windows/GUIWindowMusicBase.cpp +++ b/xbmc/music/windows/GUIWindowMusicBase.cpp @@ -62,6 +62,8 @@ #include "platform/linux/XTimeUtils.h" #endif +#include <algorithm> + using namespace XFILE; using namespace MUSICDATABASEDIRECTORY; using namespace PLAYLIST; @@ -690,12 +692,20 @@ bool CGUIWindowMusicBase::OnContextButton(int itemNumber, CONTEXT_BUTTON button) Update(item->GetPath()); int bookmark; m_musicdatabase.GetResumeBookmarkForAudioBook(item->GetPath(), bookmark); - int i=0; - while (i < m_vecItems->Size() && bookmark > m_vecItems->Get(i)->m_lEndOffset) - ++i; - CFileItem resItem(*m_vecItems->Get(i)); - resItem.SetProperty("StartPercent", ((double)bookmark-resItem.m_lStartOffset)/(resItem.m_lEndOffset-resItem.m_lStartOffset)*100); - g_application.PlayFile(resItem, "", false); + + auto itemIt = std::find_if( + m_vecItems->cbegin(), + m_vecItems->cend(), + [&](const CFileItemPtr& item) { return bookmark <= item->m_lEndOffset; } + ); + if (itemIt != m_vecItems->cend()) + { + CFileItem resItem(**itemIt); + resItem.SetProperty("StartPercent", + 100.0 * (bookmark - resItem.m_lStartOffset) / (resItem.m_lEndOffset - resItem.m_lStartOffset) + ); + g_application.PlayFile(resItem, "", false); + } } default: |