Skip to content

Commit

Permalink
lib: Fix PlayerRemote::usesPlayerRemote for empty type
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlivio committed Jun 9, 2021
1 parent a4a3e74 commit fe2a50a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
40 changes: 24 additions & 16 deletions lib/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ static map<string, PlayerPropertyInfo> player_property_map = {
{ "fontWeight", { Player::PROP_FONT_WEIGHT, true, "" } },
{ "freeze", { Player::PROP_FREEZE, true, "false" } },
{ "freq", { Player::PROP_FREQ, true, "440" } },
{ "remotePlayerBaseURL", { Player::PROP_REMOTE_PLAYER_BASE_URL, false, "" } },
{ "remotePlayerBaseURL",
{ Player::PROP_REMOTE_PLAYER_BASE_URL, false, "" } },
{ "height", { Player::PROP_HEIGHT, true, "100%" } },
{ "horzAlign", { Player::PROP_HORZ_ALIGN, true, "left" } },
{ "left", { Player::PROP_LEFT, true, "0" } },
Expand Down Expand Up @@ -546,6 +547,24 @@ Player::getPlayerProperty (const string &name, string *defval)
return info->code;
}

bool Player::getMimeForURI (const string &uri, string *result)
{
string::size_type index, len;
index = uri.find_last_of (".");
if (index != std::string::npos)
{
index++;
len = uri.length ();
if (index < len)
{
string extension = uri.substr (index, (len - index));
if (extension != "")
return mime_table_index (extension, result);
}
}
return false;
}

Player *
Player::createPlayer (Formatter *formatter, Media *media, const string &uri,
const string &type)
Expand All @@ -559,19 +578,7 @@ Player::createPlayer (Formatter *formatter, Media *media, const string &uri,

if (mime == "" && uri != "")
{
string::size_type index, len;
index = uri.find_last_of (".");
if (index != std::string::npos)
{
index++;
len = uri.length ();
if (index < len)
{
string extension = uri.substr (index, (len - index));
if (extension != "")
mime_table_index (extension, &mime);
}
}
getMimeForURI (uri, &mime);
}

if (mime == "")
Expand All @@ -598,10 +605,11 @@ Player::createPlayer (Formatter *formatter, Media *media, const string &uri,
player = new PlayerText (formatter, media);
}
// if has WS setted a remotePlayerBaseURL
else if (media->getProperty("remotePlayerBaseURL") != "")
else if (PlayerRemote::usesPlayerRemote (media))
{
player = new PlayerRemote (formatter, media);
WARNING ("Create a PlayerRemote for Media '%s'", media->getId ().c_str());
WARNING ("Create a PlayerRemote for Media '%s'",
media->getId ().c_str ());
}
#if defined WITH_CEF && WITH_CEF
else if (xstrhasprefix (mime, "text/html"))
Expand Down
1 change: 1 addition & 0 deletions lib/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Player
static string getCurrentFocus ();
static void setCurrentFocus (const string &);
static Property getPlayerProperty (const string &, string *);
static bool getMimeForURI (const string &, string*);
static Player *createPlayer (Formatter *, Media *, const string &,
const string &type = "");

Expand Down
11 changes: 7 additions & 4 deletions lib/PlayerRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ bool
PlayerRemote::usesPlayerRemote (Media *media)
{
string mime = media->getProperty ("type");
string uri = media->getProperty ("uri");
if (mime.empty ())
getMimeForURI (uri, &mime);
if (mime == REMOTE_PLAYER_MIME_NCL360)
return true;
string device = media->getProperty ("device");
Expand Down Expand Up @@ -76,10 +79,10 @@ PlayerRemote::sendAction (const string &body, const string &label = "")
if (!_session)
_session = soup_session_new ();

string url
= xstrbuild ("%s" REMOTE_PLAYER_ROUTE_NODES "%s",
getProperty ("remotePlayerBaseURL").c_str (),
(label == "") ? _media->getId ().c_str () : label.c_str ());
string url = xstrbuild ("%s" REMOTE_PLAYER_ROUTE_NODES "%s",
getProperty ("remotePlayerBaseURL").c_str (),
(label == "") ? _media->getId ().c_str ()
: label.c_str ());

msg = soup_message_new (SOUP_METHOD_POST, url.c_str ());
soup_message_set_request (msg, "application/json", SOUP_MEMORY_COPY,
Expand Down

0 comments on commit fe2a50a

Please sign in to comment.