Skip to content

Commit

Permalink
Play everything from a PlayQueue
Browse files Browse the repository at this point in the history
Create a playQueue even if we just play one item.
This had some far-reaching implications, especially for our old
PlexContentPlayerMixin that was not really going to work for PlayQueues.

The Resume/Select Media Part dialogs was moved to GUIDialogPlexMedia
and is called from MediaDecisionEngine to be able to show that when
it’s coming from a queue. This will only show for the first item in a
queue.

By removing PlexContentPlayerMixin a lot of classes had to be changed
because of include files and also because they had to call the
playQueueManager to play items instead.

This also lead to some refactoring of the way we play photos since
these are not supported by PlayQueues right now.

Fixes xbmc#1140
  • Loading branch information
Tobias Hieta committed May 8, 2014
1 parent 21392c1 commit 43b026f
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 361 deletions.
120 changes: 120 additions & 0 deletions plex/GUI/GUIDialogPlexMedia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include "GUIDialogPlexMedia.h"
#include "FileItem.h"
#include "settings/Settings.h"
#include "settings/GUISettings.h"
#include "PlexTypes.h"
#include "dialogs/GUIDialogContextMenu.h"
#include "StringUtils.h"
#include "LocalizeStrings.h"
#include "Client/PlexTranscoderClient.h"

#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include "PlexUtils.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
int CGUIDialogPlexMedia::ProcessResumeChoice(const CFileItem& file)
{
bool resumeItem = false;

if (!file.m_bIsFolder && file.HasProperty("viewOffset") &&
!file.GetProperty("viewOffset").asString().empty())
{
// Oh my god. Copy and paste code. We need a superclass which manages media.
float seconds = boost::lexical_cast<float>(file.GetProperty("viewOffset").asString()) / 1000.0f;

CContextButtons choices;
CStdString resumeString;
CStdString time = StringUtils::SecondsToTimeString(long(seconds));
resumeString.Format(g_localizeStrings.Get(12022).c_str(), time.c_str());
choices.Add(1, resumeString);
choices.Add(2, g_localizeStrings.Get(12021));
int retVal = CGUIDialogContextMenu::ShowAndGetChoice(choices);
if (retVal == -1)
return -2; // abort

resumeItem = (retVal == 1);
}

return resumeItem ? STARTOFFSET_RESUME : 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
int CGUIDialogPlexMedia::ProcessMediaChoice(const CFileItem& file)
{
int selectedMediaItem = -1;
// If there is more than one media item, allow picking which one.
if (file.m_mediaItems.size() > 1)
{
int onlineQuality = g_guiSettings.GetInt("plexmediaserver.onlinemediaquality");
bool isLibraryItem = file.IsPlexMediaServerLibrary();

// See if we're offering a choice.
if (isLibraryItem || (!isLibraryItem && onlineQuality == PLEX_ONLINE_QUALITY_ALWAYS_ASK))
{
CContextButtons choices;

for (size_t i = 0; i < file.m_mediaItems.size(); i++)
{
CFileItemPtr item = file.m_mediaItems[i];
int mpartID = item->GetProperty("id").asInteger();
if (mpartID == 0)
mpartID = i;

CStdString label = PlexUtils::GetPrettyMediaItemName(item);
choices.Add(mpartID, label);
}

int choice = CGUIDialogContextMenu::ShowAndGetChoice(choices);
if (choice >= 0)
selectedMediaItem = choice;
}
else
{
if (isLibraryItem == false)
{
// Try to pick something that's equal or less than the preferred resolution.
std::map<int, int> qualityMap;
std::vector<int> qualities;
int sd = PLEX_ONLINE_QUALITY_SD;

for (size_t i = 0; i < file.m_mediaItems.size(); i++)
{
CFileItemPtr item = file.m_mediaItems[i];
CStdString videoRes =
CStdString(item->GetProperty("mediaTag-videoResolution").asString()).ToUpper();

// Compute the quality, subsequent SDs get lesser values, assuming they're ordered
// descending.
int q = sd;
if (videoRes != "SD" && videoRes.empty() == false)
q = boost::lexical_cast<int>(videoRes);
else
sd -= 10;

qualityMap[q] = i;
qualities.push_back(q);
}

// Sort on quality descending.
std::sort(qualities.begin(), qualities.end());
std::reverse(qualities.begin(), qualities.end());

int pickedIndex = qualities[qualities.size() - 1];
BOOST_FOREACH(int q, qualities)
{
if (q <= onlineQuality)
{
pickedIndex = qualityMap[q];
selectedMediaItem = file.m_mediaItems[pickedIndex]->GetProperty("id").asInteger();
break;
}
}
}
}
}
else
selectedMediaItem = 0;

return selectedMediaItem;
}
13 changes: 13 additions & 0 deletions plex/GUI/GUIDialogPlexMedia.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef GUIDIALOGPLEXMEDIA_H
#define GUIDIALOGPLEXMEDIA_H

#include "FileItem.h"

class CGUIDialogPlexMedia
{
public:
static int ProcessResumeChoice(const CFileItem& file);
static int ProcessMediaChoice(const CFileItem& file);
};

#endif // GUIDIALOGPLEXMEDIA_H
22 changes: 12 additions & 10 deletions plex/GUI/GUIPlexMediaWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "guilib/GUILabelControl.h"
#include "GUI/GUIDialogFilterSort.h"
#include "GUIWindowManager.h"
#include "PlexContentPlayerMixin.h"
#include "ApplicationMessenger.h"
#include "dialogs/GUIDialogKaiToast.h"
#include "PlexUtils.h"
Expand All @@ -30,7 +29,6 @@
#include "utils/URIUtils.h"
#include "plex/GUI/GUIDialogPlexPluginSettings.h"
#include "PlexThemeMusicPlayer.h"
#include "PlexContentPlayerMixin.h"
#include "PlexFilterManager.h"
#include "Filters/GUIPlexFilterFactory.h"
#include "dialogs/GUIDialogBusy.h"
Expand All @@ -42,6 +40,7 @@
#include "ViewState.h"
#include "PlexPlayQueueManager.h"
#include "Client/PlexServerVersion.h"
#include "settings/GUISettings.h"

#include "LocalizeStrings.h"
#include "DirectoryCache.h"
Expand Down Expand Up @@ -744,18 +743,21 @@ bool CGUIPlexMediaWindow::OnPlayMedia(int iItem)
if (!item)
return false;

if (item->m_bIsFolder)
if (IsPhotoContainer())
{
g_plexApplication.playQueueManager->create(*item, CPlexPlayQueueManager::getURIFromItem(*item));
return true;
if (item->m_bIsFolder)
CApplicationMessenger::Get().PictureSlideShow(item->GetPath(), false);
else
CApplicationMessenger::Get().PictureSlideShow(m_vecItems->GetPath(), false, item->GetPath());
}

if (IsMusicContainer())
else if (IsMusicContainer() && !item->m_bIsFolder)
{
PlayAll(false, item);
else if (IsPhotoContainer())
CApplicationMessenger::Get().PictureSlideShow(m_vecItems->GetPath(), false, item->GetPath());
}
else
PlexContentPlayerMixin::PlayPlexItem(item);
{
g_plexApplication.playQueueManager->create(*item, CPlexPlayQueueManager::getURIFromItem(*item));
}

return true;
}
Expand Down
3 changes: 1 addition & 2 deletions plex/GUI/GUIPlexMediaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "guilib/GUIRadioButtonControl.h"
#include "StringUtils.h"
#include "JobManager.h"
#include "PlexContentPlayerMixin.h"
#include "threads/Event.h"
#include "Filters/PlexSectionFilter.h"
#include "guilib/GUIButtonControl.h"
Expand Down Expand Up @@ -45,7 +44,7 @@
class PlexMediaWindowTests;
class PlexMediaWindowUniformPropertyTests;

class CGUIPlexMediaWindow : public CGUIMediaWindow, public IJobCallback, public PlexContentPlayerMixin
class CGUIPlexMediaWindow : public CGUIMediaWindow, public IJobCallback
{
friend class PlexMediaWindowTests;
FRIEND_TEST(PlexMediaWindowTests, matchPlexFilter_basic);
Expand Down
1 change: 1 addition & 0 deletions plex/GUI/GUIWindowPlexPlayQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "PlexPlayQueueManager.h"
#include "music/tags/MusicInfoTag.h"
#include "GUIUserMessages.h"
#include "Application.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
bool CGUIWindowPlexPlayQueue::OnSelect(int iItem)
Expand Down
4 changes: 2 additions & 2 deletions plex/GUI/GUIWindowPlexPreplayVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "guilib/GUILabelControl.h"
#include "ApplicationMessenger.h"
#include "PlexApplication.h"
#include "PlexContentPlayerMixin.h"
#include "PlexThemeMusicPlayer.h"

#include "dialogs/GUIDialogBusy.h"
Expand All @@ -21,6 +20,7 @@
#include "Client/PlexServerManager.h"
#include "guilib/GUIWindowManager.h"
#include "LocalizeStrings.h"
#include "PlexPlayQueueManager.h"

#include "DirectoryCache.h"

Expand Down Expand Up @@ -78,7 +78,7 @@ bool CGUIWindowPlexPreplayVideo::OnAction(const CAction &action)

if (action.GetID() == ACTION_PLAYER_PLAY)
{
PlexContentPlayerMixin::PlayPlexItem(g_plexApplication.m_preplayItem);
g_plexApplication.playQueueManager->create(*g_plexApplication.m_preplayItem);
return true;
}
else if (action.GetID() == ACTION_TOGGLE_WATCHED)
Expand Down
4 changes: 3 additions & 1 deletion plex/GUI/GUIWindowPlexSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include "ApplicationMessenger.h"
#include "PlexThemeMusicPlayer.h"
#include "PlexJobs.h"
#include "settings/GUISettings.h"
#include "Playlists/PlexPlayQueueManager.h"

#define CTL_LABEL_EDIT 310
#define CTL_BUTTON_BACKSPACE 8
Expand Down Expand Up @@ -268,7 +270,7 @@ bool CGUIWindowPlexSearch::OnClick(int senderId, int action)
fileItem->GetPlexDirectoryType() == PLEX_DIR_TYPE_TRACK ||
fileItem->GetPlexDirectoryType() == PLEX_DIR_TYPE_PHOTO))
{
PlayPlexItem(fileItem);
g_plexApplication.playQueueManager->create(*fileItem);
return true;
}
}
Expand Down
3 changes: 1 addition & 2 deletions plex/GUI/GUIWindowPlexSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
#include "FileItem.h"
#include "guilib/GUIWindow.h"
#include "JobManager.h"
#include "PlexContentPlayerMixin.h"
#include "guilib/GUIEditControl.h"
#include "PlexGlobalTimer.h"
#include "threads/CriticalSection.h"
#include "PlexNavigationHelper.h"

class CGUIWindowPlexSearch : public CGUIWindow, public PlexContentPlayerMixin, public IJobCallback, public IPlexGlobalTimeout
class CGUIWindowPlexSearch : public CGUIWindow, public IJobCallback, public IPlexGlobalTimeout
{
public:

Expand Down
18 changes: 16 additions & 2 deletions plex/Home/GUIWindowHome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "playlists/PlayList.h"
#include "PlexPlayQueueManager.h"
#include "music/tags/MusicInfoTag.h"
#include "settings/GUISettings.h"

using namespace std;
using namespace XFILE;
Expand Down Expand Up @@ -617,7 +618,6 @@ bool CGUIWindowHome::OnClick(const CGUIMessage& message)
{
if (fileItem->HasMusicInfoTag() &&
(currentContainer == CONTENT_LIST_PLAYQUEUE_MUSIC ||
currentContainer == CONTENT_LIST_PLAYQUEUE_PHOTO ||
currentContainer == CONTENT_LIST_PLAYQUEUE_VIDEO))
{
g_plexApplication.playQueueManager->playCurrentId(fileItem->GetMusicInfoTag()->GetDatabaseId());
Expand All @@ -626,9 +626,23 @@ bool CGUIWindowHome::OnClick(const CGUIMessage& message)
{
if (iAction == ACTION_SELECT_ITEM && PlexUtils::CurrentSkinHasPreplay() &&
fileItem->GetPlexDirectoryType() != PLEX_DIR_TYPE_PHOTO)
{
OpenItem(fileItem);
}
else if (fileItem->GetPlexDirectoryType() == PLEX_DIR_TYPE_PHOTO ||
fileItem->GetPlexDirectoryType() == PLEX_DIR_TYPE_PHOTOALBUM)
{
if (fileItem->HasProperty("parentKey"))
CApplicationMessenger::Get().PictureSlideShow(fileItem->GetProperty("parentKey").asString(),
false,
fileItem->GetPath());
else
CApplicationMessenger::Get().PictureShow(fileItem->GetPath());
}
else
PlayPlexItem(fileItem, (CGUIBaseContainer*)GetFocusedControl());
{
g_plexApplication.playQueueManager->create(*fileItem);
}
}
}
else
Expand Down
3 changes: 1 addition & 2 deletions plex/Home/GUIWindowHome.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "guilib/GUIWindow.h"
#include "guilib/GUIStaticItem.h"
#include "PlexContentPlayerMixin.h"
#include "Job.h"
#include <boost/timer.hpp>

Expand All @@ -47,7 +46,7 @@

class CGUIWindowHome;

class CGUIWindowHome : public CGUIWindow, public PlexContentPlayerMixin, public IPlexGlobalTimeout, public IJobCallback
class CGUIWindowHome : public CGUIWindow, public IPlexGlobalTimeout, public IJobCallback
{
public:
CGUIWindowHome(void);
Expand Down
Loading

0 comments on commit 43b026f

Please sign in to comment.