update
This commit is contained in:
@@ -22,7 +22,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { clsx } from 'clsx';
|
||||
import type { Movie, Subtitle } from '../../types';
|
||||
import type { StreamSession } from '../../services/streaming/streamingService';
|
||||
import { searchSubtitles, downloadSubtitle, convertSrtToVtt, getAvailableLanguages } from '../../services/subtitles/opensubtitles';
|
||||
import { searchSubtitles, downloadSubtitle, convertSrtToVtt } from '../../services/subtitles/opensubtitles';
|
||||
import { useSettingsStore } from '../../stores/settingsStore';
|
||||
|
||||
interface StreamingPlayerProps {
|
||||
@@ -63,7 +63,7 @@ export default function StreamingPlayer({
|
||||
const [showSubtitles, setShowSubtitles] = useState(false);
|
||||
const [availableSubtitles, setAvailableSubtitles] = useState<Subtitle[]>([]);
|
||||
const [selectedSubtitle, setSelectedSubtitle] = useState<Subtitle | null>(null);
|
||||
const [subtitleTrack, setSubtitleTrack] = useState<TextTrack | null>(null);
|
||||
const [, setSubtitleTrack] = useState<TextTrack | null>(null);
|
||||
const [isLoadingSubtitles, setIsLoadingSubtitles] = useState(false);
|
||||
const [networkSpeed, setNetworkSpeed] = useState<number>(0);
|
||||
const [currentQualityLevel, setCurrentQualityLevel] = useState<string>('auto');
|
||||
@@ -143,7 +143,6 @@ export default function StreamingPlayer({
|
||||
highBufferWatchdogPeriod: 2, // High buffer watchdog period
|
||||
nudgeOffset: 0.1, // Nudge offset
|
||||
nudgeMaxRetry: 3, // Max retry for nudge
|
||||
maxFragLoadingTimeOut: 20000, // Max fragment loading timeout
|
||||
fragLoadingTimeOut: 20000, // Fragment loading timeout
|
||||
manifestLoadingTimeOut: 10000, // Manifest loading timeout
|
||||
levelLoadingTimeOut: 10000, // Level loading timeout
|
||||
@@ -209,12 +208,19 @@ export default function StreamingPlayer({
|
||||
|
||||
// Monitor network speed
|
||||
hls.on(Hls.Events.FRAG_LOADED, (_event, data) => {
|
||||
if (data.frag && data.stats) {
|
||||
const loadTime = (data.stats.tload - data.stats.tfirst) / 1000; // in seconds
|
||||
const bytes = data.frag.loaded;
|
||||
if (loadTime > 0 && bytes > 0) {
|
||||
const speed = (bytes / loadTime) * 8; // bits per second
|
||||
setNetworkSpeed(speed);
|
||||
if (data.frag) {
|
||||
// Try to get stats from the fragment if available
|
||||
const frag = data.frag;
|
||||
if (frag && 'stats' in frag && frag.stats) {
|
||||
const stats = frag.stats as { tload?: number; tfirst?: number };
|
||||
if (stats.tload && stats.tfirst) {
|
||||
const loadTime = (stats.tload - stats.tfirst) / 1000; // in seconds
|
||||
const bytes = (frag as any).loaded || 0;
|
||||
if (loadTime > 0 && bytes > 0) {
|
||||
const speed = (bytes / loadTime) * 8; // bits per second
|
||||
setNetworkSpeed(speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -296,7 +302,7 @@ export default function StreamingPlayer({
|
||||
}
|
||||
};
|
||||
|
||||
const handleError = (e: Event) => {
|
||||
const handleError = (_e: Event) => {
|
||||
const error = video.error;
|
||||
if (error) {
|
||||
let errorMsg = 'Unknown error';
|
||||
@@ -608,23 +614,6 @@ export default function StreamingPlayer({
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Toggle subtitles on/off
|
||||
const toggleSubtitles = useCallback(() => {
|
||||
if (!videoRef.current) return;
|
||||
|
||||
const tracks = Array.from(videoRef.current.textTracks);
|
||||
const activeTrack = tracks.find(t => t.mode === 'showing');
|
||||
|
||||
if (activeTrack) {
|
||||
activeTrack.mode = 'hidden';
|
||||
setSelectedSubtitle(null);
|
||||
} else if (selectedSubtitle) {
|
||||
const track = tracks.find(t => t.language === selectedSubtitle.language);
|
||||
if (track) {
|
||||
track.mode = 'showing';
|
||||
}
|
||||
}
|
||||
}, [selectedSubtitle]);
|
||||
|
||||
// Update volume
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user