Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added builds/android/1.4.4/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Flickv4",
"version": "1.4.3",
"version": "1.4.4",
"private": true,
"scripts": {
"clean:android": "cd android && ./gradlew clean",
Expand Down
100 changes: 53 additions & 47 deletions src/components/MediaPlayer/NetflixMediaPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
const [showSeasonDropdown, setShowSeasonDropdown] = useState(false);
const [isSeeking, setIsSeeking] = useState(false);
const [seekBarWidth, setSeekBarWidth] = useState(0);
const [bufferedPosition, setBufferedPosition] = useState(0);

const videoRef = useRef<any>(null);
const seekBarRef = useRef<View>(null);
Expand Down Expand Up @@ -305,8 +306,11 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
showControls();
}, [showControls]);

const handleProgress = useCallback(({ currentTime: t }: { currentTime: number }) => {
const handleProgress = useCallback(({ currentTime: t, playableDuration }: { currentTime: number; playableDuration?: number }) => {
if (!isSeeking) setCurrentTime(t);
if (typeof playableDuration === 'number' && Number.isFinite(playableDuration)) {
setBufferedPosition(playableDuration);
}
onPlaybackProgress(t);
}, [isSeeking, onPlaybackProgress]);

Expand All @@ -321,11 +325,14 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
}, [onEnd, onPlaybackEnd]);

const videoSource = useMemo(() => {
const isCached = playbackUrl.startsWith('file://');
return {
const useStreamHeaders =
playbackUrl.includes('.m3u8') ||
(!playbackUrl.startsWith('file://') && !playbackUrl.startsWith('/'));
Comment on lines +328 to +330
const base = {
uri: playbackUrl,
...(isCached ? {} : { headers: VIDEO_STREAM_HEADERS }),
...(useStreamHeaders ? { headers: VIDEO_STREAM_HEADERS } : {}),
};
return playbackUrl.includes('.m3u8') ? { ...base, type: 'm3u8' as const } : base;
}, [playbackUrl]);

const handleError = useCallback(() => {
Expand All @@ -346,8 +353,9 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
const next = Math.max(0, Math.min(currentTime + offset, duration));
videoRef.current.seek(next);
setCurrentTime(next);
onPlaybackProgress(next);
showControls();
}, [currentTime, duration, showControls]);
}, [currentTime, duration, onPlaybackProgress, showControls]);

// ── seekbar pan responder ──────────────────────────────────────────────────
const seekPanResponder = useMemo(() =>
Expand All @@ -374,16 +382,25 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
const t = pct * duration;
videoRef.current?.seek(t);
setCurrentTime(t);
onPlaybackProgress(t);
});
setIsSeeking(false);
showControls();
},
onPanResponderTerminate: () => setIsSeeking(false),
}),
[duration, showControls]);
[duration, onPlaybackProgress, showControls]);

// ── computed ───────────────────────────────────────────────────────────────
const progressPct = duration > 0 ? currentTime / duration : 0;
const bufferLinePct = useMemo(() => {
if (duration <= 0) return 0;
const bufferedPct = bufferedPosition / duration;
const cachedPct = cacheStatus.isActive
? Math.min((currentTime + cacheStatus.cachedSecondsAhead) / duration, 1)
: 0;
return Math.max(bufferedPct, cachedPct);
}, [bufferedPosition, cacheStatus.cachedSecondsAhead, cacheStatus.isActive, currentTime, duration]);
const thumbLeft = Math.max(0, progressPct * seekBarWidth - 8);
const hasTV = contentType === 'tv' && seasons.length > 0 && episodes.length > 0;
const currentEpisodeInfo = episodes.find(e => e.episode_number === selectedEpisode);
Expand Down Expand Up @@ -434,24 +451,26 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
return (
<View style={styles.root}>
{/* ── Video ── */}
<Video
ref={videoRef}
source={videoSource}
style={StyleSheet.absoluteFill}
resizeMode="contain"
paused={!isPlaying}
controls={false}
bufferingStrategy={BufferingStrategyType.DEPENDING_ON_MEMORY}
onLoad={handleLoad}
onProgress={handleProgress}
onBuffer={handleBuffer}
onEnd={handleEnd}
onError={handleError}
progressUpdateInterval={250}
repeat={false}
muted={false}
hideShutterView
/>
{!isCacheLoading && playbackUrl ? (
<Video
ref={videoRef}
source={videoSource}
style={StyleSheet.absoluteFill}
resizeMode="contain"
paused={!isPlaying}
controls={false}
bufferingStrategy={BufferingStrategyType.DEPENDING_ON_MEMORY}
onLoad={handleLoad}
onProgress={handleProgress}
onBuffer={handleBuffer}
onEnd={handleEnd}
onError={handleError}
progressUpdateInterval={250}
repeat={false}
muted={false}
hideShutterView
/>
) : null}

{/* ── Buffering ── */}
{(isBuffering || isCacheLoading) && (
Expand All @@ -463,14 +482,6 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
</View>
)}

{cacheStatus.isActive && cacheStatus.cachedSecondsAhead > 0 && (
<View style={styles.cacheBadge}>
<Text style={styles.cacheBadgeText}>
{Math.round(cacheStatus.cachedSecondsAhead)}s cached ahead
</Text>
</View>
)}

{/* ── Tap to toggle controls ── */}
<TouchableWithoutFeedback onPress={toggleControls}>
<View style={StyleSheet.absoluteFill} />
Expand Down Expand Up @@ -555,6 +566,9 @@ const NetflixMediaPlayer: React.FC<NetflixMediaPlayerProps> = ({
{...seekPanResponder.panHandlers}
>
<View style={styles.seekBackground} />
{bufferLinePct > 0 && (
<View style={[styles.seekBuffered, { width: bufferLinePct * seekBarWidth }]} />
)}
<View style={[styles.seekFill, { width: progressPct * seekBarWidth }]} />
{seekBarWidth > 0 && (
<View
Expand Down Expand Up @@ -706,25 +720,10 @@ const styles = StyleSheet.create({
marginTop: 12,
fontSize: 14,
},
cacheBadge: {
position: 'absolute',
top: 16,
right: 16,
backgroundColor: 'rgba(0,0,0,0.65)',
paddingHorizontal: 8,
paddingVertical: 4,
borderRadius: 4,
zIndex: 5,
},
subtitleLayer: {
...StyleSheet.absoluteFillObject,
zIndex: 3,
},
cacheBadgeText: {
color: '#fff',
fontSize: 11,
fontWeight: '600',
},
controlsOverlay: {
...StyleSheet.absoluteFillObject,
backgroundColor: 'rgba(0,0,0,0.35)',
Expand Down Expand Up @@ -843,6 +842,13 @@ const styles = StyleSheet.create({
borderRadius: 2,
backgroundColor: 'rgba(255,255,255,0.3)',
},
seekBuffered: {
position: 'absolute',
left: 0,
height: 4,
borderRadius: 2,
backgroundColor: 'rgba(255,255,255,0.55)',
},
seekFill: {
position: 'absolute',
left: 0,
Expand Down
74 changes: 10 additions & 64 deletions src/components/MediaPlayer/SubtitleOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { useState, useEffect, useMemo } from 'react';
import { View, Text, ViewStyle, TextStyle, Platform } from 'react-native';
import { SubtitleStyle, DEFAULT_SUBTITLE_STYLE } from '../../types';

interface SubtitleCue {
start: number;
end: number;
text: string;
}
import { findActiveCue, parseSrtCues } from '../../utils/subtitleUtils';

interface SubtitleOverlayProps {
subtitleContent: string | null;
Expand All @@ -17,47 +12,6 @@ interface SubtitleOverlayProps {
style?: SubtitleStyle;
}

const parseSRT = (srtContent: string): SubtitleCue[] => {
const cues: SubtitleCue[] = [];

const blocks = srtContent.trim().split(/\r?\n\r?\n/);

for (const block of blocks) {
const lines = block.trim().split(/\r?\n/);
if (lines.length < 3) continue;

const timestampIndex = lines.findIndex(line => line.includes('-->'));
if (timestampIndex === -1) continue;

const timestampLine = lines[timestampIndex];
const textLines = lines.slice(timestampIndex + 1);

const match = timestampLine.match(/(\d{2}):(\d{2}):(\d{2}),(\d{3})\s*-->\s*(\d{2}):(\d{2}):(\d{2}),(\d{3})/);
if (!match) continue;

const startHours = parseInt(match[1], 10);
const startMinutes = parseInt(match[2], 10);
const startSeconds = parseFloat(`${match[3]}.${match[4]}`);
const endHours = parseInt(match[5], 10);
const endMinutes = parseInt(match[6], 10);
const endSeconds = parseFloat(`${match[7]}.${match[8]}`);

const start = startHours * 3600 + startMinutes * 60 + startSeconds;
const end = endHours * 3600 + endMinutes * 60 + endSeconds;

const text = textLines
.join('\n')
.replace(/<[^>]*>/g, '')
.trim();

if (text) {
cues.push({ start, end, text });
}
}

return cues;
};

export const SubtitleOverlay: React.FC<SubtitleOverlayProps> = ({
subtitleContent,
currentTime,
Expand All @@ -66,8 +20,9 @@ export const SubtitleOverlay: React.FC<SubtitleOverlayProps> = ({
delay = 0,
style = DEFAULT_SUBTITLE_STYLE,
}) => {
const [cues, setCues] = useState<SubtitleCue[]>([]);
const [currentCue, setCurrentCue] = useState<string | null>(null);
const [cues, setCues] = useState(() =>
subtitleContent ? parseSrtCues(subtitleContent) : [],
);

const computedFontSize = useMemo(() => {
const baseSizes = {
Expand Down Expand Up @@ -124,28 +79,19 @@ export const SubtitleOverlay: React.FC<SubtitleOverlayProps> = ({
useEffect(() => {
if (subtitleContent) {
try {
const parsedCues = parseSRT(subtitleContent);
setCues(parsedCues);
setCues(parseSrtCues(subtitleContent));
} catch {
setCues([]);
}
} else {
setCues([]);
setCurrentCue(null);
}
}, [subtitleContent]);

useEffect(() => {
if (cues.length === 0) {
setCurrentCue(null);
return;
}

const adjustedTime = currentTime - delay + 0.5;
const activeCue = cues.find(
cue => adjustedTime >= cue.start && adjustedTime <= cue.end
);

setCurrentCue(activeCue ? activeCue.text : null);
const currentCue = useMemo(() => {
if (cues.length === 0) return null;
const adjustedTime = currentTime - delay;
return findActiveCue(cues, adjustedTime)?.text ?? null;
}, [currentTime, cues, delay]);

if (!currentCue) {
Expand Down
2 changes: 2 additions & 0 deletions src/components/MediaPlayer/controls/BottomBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const BottomBar: React.FC<BottomBarProps> = ({
subtitleDelay = 0,
onSubtitleDelayChange,
onResetSubtitleDelay,
cachedAheadSeconds = 0,
}) => {
const [showDelayControls, setShowDelayControls] = useState(false);

Expand Down Expand Up @@ -61,6 +62,7 @@ export const BottomBar: React.FC<BottomBarProps> = ({
currentPosition={currentPosition}
duration={duration}
bufferedPosition={bufferedPosition}
cachedAheadSeconds={cachedAheadSeconds}
hidden={hidden}
onSeek={onSeek}
onTimePreview={onTimePreview}
Expand Down
9 changes: 2 additions & 7 deletions src/components/MediaPlayer/controls/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ControlsComponent: React.FC<ControlsProps> = ({
subtitleDelay = 0,
onSubtitleDelayChange,
onResetSubtitleDelay,
cacheAheadSeconds,
cachedAheadSeconds = 0,
}) => {
const navigation = useNavigation();
const [timeLabel, setTimeLabel] = useState<string>(formatTime(0));
Expand Down Expand Up @@ -178,14 +178,9 @@ const ControlsComponent: React.FC<ControlsProps> = ({
subtitleDelay={subtitleDelay}
onSubtitleDelayChange={onSubtitleDelayChange}
onResetSubtitleDelay={onResetSubtitleDelay}
cachedAheadSeconds={cachedAheadSeconds}
/>

{cacheAheadSeconds !== undefined && cacheAheadSeconds > 0 && !isControlsHidden && (
<View style={styles.cacheBadge}>
<Text style={styles.cacheBadgeText}>{cacheAheadSeconds}s cached ahead</Text>
</View>
)}

{readyNext && fullscreen && onNext && (
<View
style={[
Expand Down
18 changes: 15 additions & 3 deletions src/components/MediaPlayer/controls/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ProgressBarComponent: React.FC<ProgressBarProps> = ({
currentPosition,
duration,
bufferedPosition = 0,
cachedAheadSeconds = 0,
hidden,
onSeek,
onTimePreview,
Expand All @@ -30,6 +31,17 @@ const ProgressBarComponent: React.FC<ProgressBarProps> = ({
return clamp(bufferedPosition / duration, 0, 1);
}, [bufferedPosition, duration]);

const cachedPercentage = useMemo(() => {
if (!duration || duration === 0 || cachedAheadSeconds <= 0) return 0;
const cachedEnd = currentPosition + cachedAheadSeconds;
return clamp(cachedEnd / duration, 0, 1);
}, [cachedAheadSeconds, currentPosition, duration]);

const bufferLinePercentage = useMemo(
() => Math.max(bufferedPercentage, cachedPercentage),
[bufferedPercentage, cachedPercentage],
);

useEffect(() => {
if (!isDragging) {
dragPercentageRef.current = progressPercentage;
Expand Down Expand Up @@ -91,8 +103,8 @@ const ProgressBarComponent: React.FC<ProgressBarProps> = ({
const displayPercentage = isDragging ? dragPercentage : progressPercentage;

const bufferedStyle = useMemo(() => ({
width: bufferedPercentage * trackWidth,
}), [bufferedPercentage, trackWidth]);
width: bufferLinePercentage * trackWidth,
}), [bufferLinePercentage, trackWidth]);

const progressStyle = useMemo(() => ({
width: displayPercentage * trackWidth,
Expand All @@ -113,7 +125,7 @@ const ProgressBarComponent: React.FC<ProgressBarProps> = ({
<View style={styles.progressTouchArea} {...panResponder.panHandlers}>
<View ref={trackRef} style={styles.progressTrack}>
<View style={styles.progressBackground} />
{bufferedPercentage > 0 && <View style={[styles.progressBuffered, bufferedStyle]} />}
{bufferLinePercentage > 0 && <View style={[styles.progressBuffered, bufferedStyle]} />}
<View style={[styles.progressForeground, progressStyle]} />
<Animated.View style={[styles.progressThumb, thumbStyle]} />
</View>
Expand Down
Loading