Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / xbmc / utils / PlayerUtils.cpp
blobf3545a835f863b64e1317c789573ac630fcd7be1
1 /*
2 * Copyright (C) 2022 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PlayerUtils.h"
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "application/ApplicationPlayer.h"
14 #include "cores/playercorefactory/PlayerCoreFactory.h"
15 #include "music/MusicUtils.h"
16 #include "utils/Variant.h"
17 #include "video/VideoFileItemClassify.h"
18 #include "video/guilib/VideoGUIUtils.h"
20 using namespace KODI;
22 bool CPlayerUtils::IsItemPlayable(const CFileItem& itemIn)
24 const CFileItem item(itemIn.GetItemToPlay());
26 // General
27 if (item.IsParentFolder())
28 return false;
30 // Plugins
31 if (item.IsPlugin() && item.GetProperty("isplayable").asBoolean())
32 return true;
34 // Music
35 if (MUSIC_UTILS::IsItemPlayable(item))
36 return true;
38 // Movies / TV Shows / Music Videos
39 if (VIDEO::UTILS::IsItemPlayable(item))
40 return true;
42 //! @todo add more types on demand.
44 return false;
47 void CPlayerUtils::AdvanceTempoStep(const std::shared_ptr<CApplicationPlayer>& appPlayer,
48 TempoStepChange change)
50 const auto step = 0.1f;
51 const auto currentTempo = appPlayer->GetPlayTempo();
52 switch (change)
54 case TempoStepChange::INCREASE:
55 appPlayer->SetTempo(currentTempo + step);
56 break;
57 case TempoStepChange::DECREASE:
58 appPlayer->SetTempo(currentTempo - step);
59 break;
63 std::vector<std::string> CPlayerUtils::GetPlayersForItem(const CFileItem& item)
65 const CPlayerCoreFactory& playerCoreFactory{CServiceBroker::GetPlayerCoreFactory()};
67 std::vector<std::string> players;
68 if (VIDEO::IsVideoDb(item))
70 //! @todo CPlayerCoreFactory and classes called from there do not handle dyn path correctly.
71 CFileItem item2{item};
72 item2.SetPath(item.GetDynPath());
73 playerCoreFactory.GetPlayers(item2, players);
75 else
77 playerCoreFactory.GetPlayers(item, players);
80 return players;
83 bool CPlayerUtils::HasItemMultiplePlayers(const CFileItem& item)
85 return GetPlayersForItem(item).size() > 1;