mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-01 21:24:52 +00:00
test fix poster loading
This commit is contained in:
parent
292d00af84
commit
87455ff573
3 changed files with 54 additions and 28 deletions
|
|
@ -61,6 +61,7 @@ const ContentItem = ({ item, onPress }: ContentItemProps) => {
|
||||||
const [imageLoaded, setImageLoaded] = useState(false);
|
const [imageLoaded, setImageLoaded] = useState(false);
|
||||||
const [imageError, setImageError] = useState(false);
|
const [imageError, setImageError] = useState(false);
|
||||||
const [shouldLoadImage, setShouldLoadImage] = useState(false);
|
const [shouldLoadImage, setShouldLoadImage] = useState(false);
|
||||||
|
const [retryCount, setRetryCount] = useState(0);
|
||||||
const { currentTheme } = useTheme();
|
const { currentTheme } = useTheme();
|
||||||
|
|
||||||
// Intersection observer simulation for lazy loading
|
// Intersection observer simulation for lazy loading
|
||||||
|
|
@ -101,14 +102,21 @@ const ContentItem = ({ item, onPress }: ContentItemProps) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setShouldLoadImage(true);
|
setShouldLoadImage(true);
|
||||||
}, 100); // Small delay to avoid loading offscreen items
|
}, 50); // Reduced delay for faster loading
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Get optimized poster URL for smaller tiles
|
// Get optimized poster URL for smaller tiles
|
||||||
const getOptimizedPosterUrl = useCallback((originalUrl: string) => {
|
const getOptimizedPosterUrl = useCallback((originalUrl: string) => {
|
||||||
if (!originalUrl) return 'https://via.placeholder.com/154x231/333/666?text=No+Image';
|
if (!originalUrl || originalUrl.includes('placeholder')) {
|
||||||
|
return 'https://via.placeholder.com/154x231/333/666?text=No+Image';
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've had an error, try metahub fallback
|
||||||
|
if (retryCount > 0 && !originalUrl.includes('metahub.space')) {
|
||||||
|
return `https://images.metahub.space/poster/small/${item.id}/img`;
|
||||||
|
}
|
||||||
|
|
||||||
// For TMDB images, use smaller sizes
|
// For TMDB images, use smaller sizes
|
||||||
if (originalUrl.includes('image.tmdb.org')) {
|
if (originalUrl.includes('image.tmdb.org')) {
|
||||||
|
|
@ -116,10 +124,14 @@ const ContentItem = ({ item, onPress }: ContentItemProps) => {
|
||||||
return originalUrl.replace(/\/w\d+\//, '/w154/');
|
return originalUrl.replace(/\/w\d+\//, '/w154/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// For other sources, try to add size parameters
|
// For metahub images, use smaller sizes
|
||||||
const separator = originalUrl.includes('?') ? '&' : '?';
|
if (originalUrl.includes('images.metahub.space')) {
|
||||||
return `${originalUrl}${separator}w=154&h=231&q=75`;
|
return originalUrl.replace('/medium/', '/small/');
|
||||||
}, []);
|
}
|
||||||
|
|
||||||
|
// Return original URL for other sources to avoid breaking them
|
||||||
|
return originalUrl;
|
||||||
|
}, [retryCount, item.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -138,8 +150,8 @@ const ContentItem = ({ item, onPress }: ContentItemProps) => {
|
||||||
source={{ uri: getOptimizedPosterUrl(item.poster) }}
|
source={{ uri: getOptimizedPosterUrl(item.poster) }}
|
||||||
style={[styles.poster, { backgroundColor: currentTheme.colors.elevation1 }]}
|
style={[styles.poster, { backgroundColor: currentTheme.colors.elevation1 }]}
|
||||||
contentFit="cover"
|
contentFit="cover"
|
||||||
cachePolicy="disk" // Disk-only cache to save RAM
|
cachePolicy="memory-disk" // Use both memory and disk cache
|
||||||
transition={0}
|
transition={200} // Add smooth transition
|
||||||
placeholder={{ blurhash: PLACEHOLDER_BLURHASH } as any}
|
placeholder={{ blurhash: PLACEHOLDER_BLURHASH } as any}
|
||||||
placeholderContentFit="cover"
|
placeholderContentFit="cover"
|
||||||
allowDownscaling
|
allowDownscaling
|
||||||
|
|
@ -147,11 +159,19 @@ const ContentItem = ({ item, onPress }: ContentItemProps) => {
|
||||||
setImageLoaded(true);
|
setImageLoaded(true);
|
||||||
setImageError(false);
|
setImageError(false);
|
||||||
}}
|
}}
|
||||||
onError={() => {
|
onError={(error) => {
|
||||||
|
console.warn('Image load error for:', item.poster, error);
|
||||||
|
// Try fallback URL on first error
|
||||||
|
if (retryCount === 0 && item.poster && !item.poster.includes('metahub.space')) {
|
||||||
|
setRetryCount(1);
|
||||||
|
// Don't set error state yet, let it try the fallback
|
||||||
|
return;
|
||||||
|
}
|
||||||
setImageError(true);
|
setImageError(true);
|
||||||
setImageLoaded(false);
|
setImageLoaded(false);
|
||||||
}}
|
}}
|
||||||
priority="low"
|
priority="normal" // Increase priority for better loading
|
||||||
|
recyclingKey={item.id} // Add recycling key for better performance
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
// Show placeholder until lazy load triggers
|
// Show placeholder until lazy load triggers
|
||||||
|
|
@ -199,7 +219,7 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
contentItem: {
|
contentItem: {
|
||||||
width: POSTER_WIDTH,
|
width: POSTER_WIDTH,
|
||||||
aspectRatio: 2/3,
|
aspectRatio: 2 / 3,
|
||||||
margin: 0,
|
margin: 0,
|
||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
|
|
|
||||||
|
|
@ -568,11 +568,17 @@ class CatalogService {
|
||||||
|
|
||||||
private convertMetaToStreamingContent(meta: Meta): StreamingContent {
|
private convertMetaToStreamingContent(meta: Meta): StreamingContent {
|
||||||
// Basic conversion for catalog display - no enhanced metadata processing
|
// Basic conversion for catalog display - no enhanced metadata processing
|
||||||
|
// Validate poster URL and provide better fallback
|
||||||
|
let posterUrl = meta.poster;
|
||||||
|
if (!posterUrl || posterUrl.trim() === '' || posterUrl === 'null' || posterUrl === 'undefined') {
|
||||||
|
posterUrl = `https://images.metahub.space/poster/medium/${meta.id}/img`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: meta.id,
|
id: meta.id,
|
||||||
type: meta.type,
|
type: meta.type,
|
||||||
name: meta.name,
|
name: meta.name,
|
||||||
poster: meta.poster || 'https://via.placeholder.com/300x450/cccccc/666666?text=No+Image',
|
poster: posterUrl,
|
||||||
posterShape: 'poster',
|
posterShape: 'poster',
|
||||||
banner: meta.background,
|
banner: meta.background,
|
||||||
logo: `https://images.metahub.space/logo/medium/${meta.id}/img`, // Use metahub for catalog display
|
logo: `https://images.metahub.space/logo/medium/${meta.id}/img`, // Use metahub for catalog display
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@ interface CachedImage {
|
||||||
|
|
||||||
class ImageCacheService {
|
class ImageCacheService {
|
||||||
private cache = new Map<string, CachedImage>();
|
private cache = new Map<string, CachedImage>();
|
||||||
private readonly CACHE_DURATION = 12 * 60 * 60 * 1000; // Reduced to 12 hours
|
private readonly CACHE_DURATION = 24 * 60 * 60 * 1000; // 24 hours
|
||||||
private readonly MAX_CACHE_SIZE = 50; // Reduced maximum number of cached images
|
private readonly MAX_CACHE_SIZE = 100; // Increased maximum number of cached images
|
||||||
private readonly MAX_MEMORY_MB = 100; // Maximum memory usage in MB
|
private readonly MAX_MEMORY_MB = 150; // Increased maximum memory usage in MB
|
||||||
private currentMemoryUsage = 0;
|
private currentMemoryUsage = 0;
|
||||||
private cleanupInterval: NodeJS.Timeout | null = null;
|
private cleanupInterval: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
|
@ -44,9 +44,9 @@ class ImageCacheService {
|
||||||
return cached.localPath;
|
return cached.localPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check memory pressure before adding new entries
|
// Check memory pressure before adding new entries (more lenient)
|
||||||
if (this.shouldSkipCaching()) {
|
if (this.cache.size >= this.MAX_CACHE_SIZE * 0.95) {
|
||||||
logger.log(`[ImageCache] Skipping cache due to memory pressure`);
|
logger.log(`[ImageCache] Skipping cache due to size limit`);
|
||||||
return originalUrl;
|
return originalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue