Skip to content

Commit

Permalink
Merge pull request xbmc#24926 from neo1973/fix_24850
Browse files Browse the repository at this point in the history
[Android TV] fixed cover display for channels
  • Loading branch information
neo1973 committed Apr 26, 2024
2 parents 8dc1756 + e28f497 commit 9bd1b8f
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 21 deletions.
1 change: 1 addition & 0 deletions cmake/scripts/android/Install.cmake
Expand Up @@ -48,6 +48,7 @@ set(package_files strings.xml
src/XBMCProperties.java
src/XBMCVideoView.java
src/XBMCFile.java
src/XBMCTextureCache.java
src/XBMCURIUtils.java
src/channels/SyncChannelJobService.java
src/channels/SyncProgramsJobService.java
Expand Down
63 changes: 42 additions & 21 deletions tools/android/packaging/xbmc/src/XBMCJsonRPC.java.in
Expand Up @@ -24,15 +24,15 @@ import android.net.Uri;
import android.provider.BaseColumns;
import android.util.Log;

import @APP_PACKAGE@.content.XBMCFileContentProvider;
import @APP_PACKAGE@.model.Album;
import @APP_PACKAGE@.model.File;
import @APP_PACKAGE@.model.Media;
import @APP_PACKAGE@.model.Movie;
import @APP_PACKAGE@.model.MusicVideo;
import @APP_PACKAGE@.model.Song;
import @APP_PACKAGE@.model.TVEpisode;
import @APP_PACKAGE@.model.TVShow;
import @APP_PACKAGE@.content.XBMCFileContentProvider;
import @APP_PACKAGE@.model.File;
import @APP_PACKAGE@.model.Media;

public class XBMCJsonRPC
{
Expand Down Expand Up @@ -63,6 +63,7 @@ public class XBMCJsonRPC

private String m_xbmc_web_url = "http://localhost:8080";
private HashSet<Integer> mRecomendationIds = new HashSet<Integer>();
private XBMCTextureCache mTextureCache = null;

private int MAX_RECOMMENDATIONS = 3;

Expand Down Expand Up @@ -126,6 +127,7 @@ public class XBMCJsonRPC
{
String jsonPort = XBMCProperties.getStringProperty("xbmc.jsonPort", "8080");
m_xbmc_web_url = "http://localhost:" + jsonPort;
mTextureCache = new XBMCTextureCache();
}

public String request_string(String jsonRequest)
Expand Down Expand Up @@ -864,7 +866,7 @@ public class XBMCJsonRPC
String poster = extractKeyFromArtMap(details, "poster");
if (poster != null && !poster.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(poster).toString());
med.setCardImageUrl(getImageUrl(poster));
med.setCardImageAspectRatio("2:3");
}
// fallback to thumb
Expand All @@ -873,15 +875,15 @@ public class XBMCJsonRPC
poster = extractKeyFromArtMap(details, "thumb");
if (poster != null && !poster.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(poster).toString());
med.setCardImageUrl(getImageUrl(poster));
med.setCardImageAspectRatio("16:9");
}
}
// fanart
String fanart = extractKeyFromArtMap(details, "fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}

med.setXbmcUrl("videodb://movies/titles/" + details.get("movieid").getAsString() + "?showinfo=true");
Expand Down Expand Up @@ -935,7 +937,7 @@ public class XBMCJsonRPC
String poster = extractKeyFromArtMap(details, "poster");
if (poster != null && !poster.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(poster).toString());
med.setCardImageUrl(getImageUrl(poster));
med.setCardImageAspectRatio("2:3");
}
// fallback to thumb
Expand All @@ -944,15 +946,15 @@ public class XBMCJsonRPC
poster = extractKeyFromArtMap(details, "thumb");
if (poster != null && !poster.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(poster).toString());
med.setCardImageUrl(getImageUrl(poster));
med.setCardImageAspectRatio("16:9");
}
}
// fanart
String fanart = extractKeyFromArtMap(details, "fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}
med.setXbmcUrl("videodb://tvshows/titles/" + details.get("tvshowid").getAsInt() + "/");
med.setCategory(Media.MEDIA_TYPE_TVSHOW);
Expand Down Expand Up @@ -982,14 +984,14 @@ public class XBMCJsonRPC
String thumb = extractKeyFromArtMap(details, "thumb");
if (thumb != null && !thumb.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(thumb).toString());
med.setCardImageUrl(getImageUrl(thumb));
med.setCardImageAspectRatio("16:9");
}
// fanart
String fanart = extractKeyFromArtMap(details, "fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}

med.setXbmcUrl("videodb://tvshows/titles/" + details.get("tvshowid").getAsInt() + "/" + details.get("episodeid").getAsInt() + "?showinfo=true");
Expand Down Expand Up @@ -1029,14 +1031,14 @@ public class XBMCJsonRPC
String thumb = extractKeyFromArtMap(details, "thumb");
if (thumb != null && !thumb.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(thumb).toString());
med.setCardImageUrl(getImageUrl(thumb));
med.setCardImageAspectRatio("1:1");
}
// fanart
String fanart = extractKeyFromArtMap(details, "fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}

med.setXbmcUrl("musicdb://albums/" + details.get("albumid").getAsString() + "/");
Expand Down Expand Up @@ -1064,7 +1066,7 @@ public class XBMCJsonRPC
String thumb = extractKeyFromArtMap(details, "album.thumb");
if (thumb != null && !thumb.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(thumb).toString());
med.setCardImageUrl(getImageUrl(thumb));
med.setCardImageAspectRatio("1:1");
}
// fallback to albumartist.thumb
Expand All @@ -1073,7 +1075,7 @@ public class XBMCJsonRPC
thumb = extractKeyFromArtMap(details, "albumartist.thumb");
if (thumb != null && !thumb.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(thumb).toString());
med.setCardImageUrl(getImageUrl(thumb));
med.setCardImageAspectRatio("1:1");
}
else
Expand All @@ -1082,7 +1084,7 @@ public class XBMCJsonRPC
thumb = extractKeyFromArtMap(details, "artist.thumb");
if (thumb != null && !thumb.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(thumb).toString());
med.setCardImageUrl(getImageUrl(thumb));
med.setCardImageAspectRatio("1:1");
}
}
Expand All @@ -1091,14 +1093,14 @@ public class XBMCJsonRPC
String fanart = extractKeyFromArtMap(details, "albumartist.fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}
else
{
fanart = extractKeyFromArtMap(details, "artist.fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}
}

Expand Down Expand Up @@ -1145,21 +1147,21 @@ public class XBMCJsonRPC
String thumb = extractKeyFromArtMap(details, "thumb");
if (thumb != null && !thumb.isEmpty())
{
med.setCardImageUrl(XBMCFileContentProvider.buildUri(thumb).toString());
med.setCardImageUrl(getImageUrl(thumb));
med.setCardImageAspectRatio("1:1");
}
// fanart
String fanart = extractKeyFromArtMap(details, "fanart");
if (fanart != null && !fanart.isEmpty())
{
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(fanart).toString());
med.setBackgroundImageUrl(getImageUrl(fanart));
}

med.setXbmcUrl("videodb://musicvideos/titles/" + details.get("musicvideoid").getAsInt());

String url = getDownloadUrl(details.get("file").getAsString());
if (url != null && !url.isEmpty())
med.setVideoUrl(XBMCFileContentProvider.buildUri(url).toString());
med.setVideoUrl(getImageUrl(url));

med.setCategory(Media.MEDIA_TYPE_MUSICVIDEO);
}
Expand Down Expand Up @@ -1438,4 +1440,23 @@ public class XBMCJsonRPC
return String.valueOf(rating / 2.0);
}

private String getImageUrl(String sUrl)
{
Log.d(TAG, "getImageUrl: sUrl = " + sUrl);
if (sUrl.startsWith("image://video@") || sUrl.startsWith("image://music@"))
{
Log.d(TAG, "getImageUrl: " + sUrl + " is not unwrapped");
return XBMCFileContentProvider.buildUri(sUrl).toString();
}

String sUnwrapImageUrl = this.mTextureCache.unwrapImageURL(sUrl);
Log.d(TAG, "getImageUrl: sUnwrapImageUrl = " + sUnwrapImageUrl);
if (!sUnwrapImageUrl.startsWith("http"))
{
return XBMCFileContentProvider.buildUri(sUrl).toString();
}

return sUnwrapImageUrl;
}

}
32 changes: 32 additions & 0 deletions tools/android/packaging/xbmc/src/XBMCTextureCache.java.in
@@ -0,0 +1,32 @@
package @APP_PACKAGE@;

import android.util.Log;

/**
* Created by Maven85 on 16/03/2020.
*/

public class XBMCTextureCache
{
native String _unwrapImageURL(String image);

private static final String TAG = "@APP_NAME@";

public XBMCTextureCache()
{
}

public String unwrapImageURL(String image)
{
try
{
return _unwrapImageURL(image);
}
catch (Exception e)
{
Log.e(TAG, "unwrapImageURL: Exception: " + e.getMessage());
return null;
}
}

}
2 changes: 2 additions & 0 deletions xbmc/platform/android/activity/CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ set(SOURCES android_main.cpp
JNIXBMCNsdManagerResolveListener.cpp
JNIXBMCJsonHandler.cpp
JNIXBMCFile.cpp
JNIXBMCTextureCache.cpp
JNIXBMCURIUtils.cpp
JNIXBMCDisplayManagerDisplayListener.cpp
JNIXBMCSpeechRecognitionListener.cpp
Expand All @@ -42,6 +43,7 @@ set(HEADERS AndroidFeatures.h
JNIXBMCNsdManagerResolveListener.h
JNIXBMCJsonHandler.h
JNIXBMCFile.h
JNIXBMCTextureCache.h
JNIXBMCURIUtils.h
JNIXBMCDisplayManagerDisplayListener.h
JNIXBMCSpeechRecognitionListener.h
Expand Down
42 changes: 42 additions & 0 deletions xbmc/platform/android/activity/JNIXBMCTextureCache.cpp
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2020 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#include "JNIXBMCTextureCache.h"

#include "CompileInfo.h"
#include "TextureCache.h"

#include <androidjni/Context.h>
#include <androidjni/jutils-details.hpp>

using namespace jni;

static std::string s_className = std::string(CCompileInfo::GetClass()) + "/XBMCTextureCache";

void CJNIXBMCTextureCache::RegisterNatives(JNIEnv* env)
{
jclass cClass = env->FindClass(s_className.c_str());
if (cClass)
{
JNINativeMethod methods[] = {
{"_unwrapImageURL", "(Ljava/lang/String;)Ljava/lang/String;",
(void*)&CJNIXBMCTextureCache::_unwrapImageURL},
};

env->RegisterNatives(cClass, methods, sizeof(methods) / sizeof(methods[0]));
}
}

jstring CJNIXBMCTextureCache::_unwrapImageURL(JNIEnv* env, jobject thiz, jstring image)
{
std::string strImage = jcast<std::string>(jhstring::fromJNI(image));
std::string responseData = CTextureUtils::UnwrapImageURL(strImage);

jstring jres = env->NewStringUTF(responseData.c_str());
return jres;
}
29 changes: 29 additions & 0 deletions xbmc/platform/android/activity/JNIXBMCTextureCache.h
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2020 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

#include <androidjni/JNIBase.h>

namespace jni
{

class CJNIXBMCTextureCache : public CJNIBase
{
public:
CJNIXBMCTextureCache(const jni::jhobject& object) : CJNIBase(object) {}

static void RegisterNatives(JNIEnv* env);

protected:
~CJNIXBMCTextureCache() override = default;

static jstring _unwrapImageURL(JNIEnv* env, jobject thiz, jstring image);
};

} // namespace jni
2 changes: 2 additions & 0 deletions xbmc/platform/android/activity/android_main.cpp
Expand Up @@ -23,6 +23,7 @@
#include "platform/android/activity/JNIXBMCNsdManagerResolveListener.h"
#include "platform/android/activity/JNIXBMCSpeechRecognitionListener.h"
#include "platform/android/activity/JNIXBMCSurfaceTextureOnFrameAvailableListener.h"
#include "platform/android/activity/JNIXBMCTextureCache.h"
#include "platform/android/activity/JNIXBMCURIUtils.h"
#include "platform/android/activity/JNIXBMCVideoView.h"

Expand Down Expand Up @@ -127,6 +128,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
CJNIXBMCNsdManagerResolveListener::RegisterNatives(env);
CJNIXBMCSpeechRecognitionListener::RegisterNatives(env);
CJNIXBMCSurfaceTextureOnFrameAvailableListener::RegisterNatives(env);
CJNIXBMCTextureCache::RegisterNatives(env);
CJNIXBMCURIUtils::RegisterNatives(env);
CJNIXBMCVideoView::RegisterNatives(env);

Expand Down

0 comments on commit 9bd1b8f

Please sign in to comment.