Anonymous
Safari не может воспроизводить видео MP4 от Backend Strapi (работает в Chrome, CORS).
Сообщение
Anonymous » 11 сен 2025, 23:12
Я обслуживаю видеофайлы MP4 из бэкэнда Strapi, и они хорошо играют в Chrome, но терпят неудачу в сафари.
Код: Выделить всё
Unhandled Promise Rejection: AbortError: The operation was aborted.< /code> < /p>
Что я пробовал до сих пор: < /p>
[*] Попытался регулировать Cors в Strapi middlewares.js < /li>
< /ol>
{
name: 'strapi::cors',
config: {
origin: ['http://localhost:3000'], or //origin: ['*'],
methods: ['GET', 'HEAD', 'OPTIONS'],
headers: ['Content-Type', 'Authorization', 'Range'],
exposeHeaders: ['Content-Length', 'Content-Range'],
credentials: false,
keepHeaderOnError: true,
},
}
Добавлен Playsinline и приглушение атрибуты к видеотете
добавлен? /> Но, очевидно, ничего не помогло < /p>
Код ниже: < /p>
Код: Выделить всё
'use client';
// imports...
export const VideoComponent: FC = ({
video,
poster,
isVideoOnGrid,
maxWidthMobile,
maxWidthDesktop,
}) => {
const videoRef = useRef(null);
const [isPlaying, setIsPlaying] = useState(false);
const data = video.data.attributes;
const posterData = poster?.data?.attributes;
const src = data.url ? getAssetUrlPrefix() + data.url : '';
useEffect(() => {
const videoElement = videoRef.current;
if (!videoElement) return;
const handlePlay = () => setIsPlaying(true);
const handlePause = () => setIsPlaying(false);
videoElement.addEventListener('play', handlePlay);
videoElement.addEventListener('pause', handlePause);
return () => {
videoElement.removeEventListener('play', handlePlay);
videoElement.removeEventListener('pause', handlePause);
};
}, []);
const togglePlay = () => {
if (videoRef.current) {
if (isPlaying) {
videoRef.current.pause();
} else {
videoRef.current.play();
}
setIsPlaying(!isPlaying);
}
};
return (
console.log('Video can play through')}
onError={(e) => console.error('Video Error:', e)}
playsInline
preload="auto"
ref={videoRef}
width="100%"
poster={`${posterData?.url ? getAssetUrlPrefix() + posterData.url : ''}`}
>
Your browser does not support the video tag.
);
};
Любая помощь будет оценена
Подробнее здесь:
https://stackoverflow.com/questions/797 ... ors-issues
1757621534
Anonymous
Я обслуживаю видеофайлы MP4 из бэкэнда Strapi, и они хорошо играют в Chrome, но терпят неудачу в сафари.[code]Unhandled Promise Rejection: AbortError: The operation was aborted.< /code> < /p> Что я пробовал до сих пор: < /p> [*] Попытался регулировать Cors в Strapi middlewares.js < /li> < /ol> { name: 'strapi::cors', config: { origin: ['http://localhost:3000'], or //origin: ['*'], methods: ['GET', 'HEAD', 'OPTIONS'], headers: ['Content-Type', 'Authorization', 'Range'], exposeHeaders: ['Content-Length', 'Content-Range'], credentials: false, keepHeaderOnError: true, }, } [/code] Добавлен Playsinline и приглушение атрибуты к видеотете добавлен? /> Но, очевидно, ничего не помогло < /p> Код ниже: < /p> [code] 'use client'; // imports... export const VideoComponent: FC = ({ video, poster, isVideoOnGrid, maxWidthMobile, maxWidthDesktop, }) => { const videoRef = useRef(null); const [isPlaying, setIsPlaying] = useState(false); const data = video.data.attributes; const posterData = poster?.data?.attributes; const src = data.url ? getAssetUrlPrefix() + data.url : ''; useEffect(() => { const videoElement = videoRef.current; if (!videoElement) return; const handlePlay = () => setIsPlaying(true); const handlePause = () => setIsPlaying(false); videoElement.addEventListener('play', handlePlay); videoElement.addEventListener('pause', handlePause); return () => { videoElement.removeEventListener('play', handlePlay); videoElement.removeEventListener('pause', handlePause); }; }, []); const togglePlay = () => { if (videoRef.current) { if (isPlaying) { videoRef.current.pause(); } else { videoRef.current.play(); } setIsPlaying(!isPlaying); } }; return ( console.log('Video can play through')} onError={(e) => console.error('Video Error:', e)} playsInline preload="auto" ref={videoRef} width="100%" poster={`${posterData?.url ? getAssetUrlPrefix() + posterData.url : ''}`} > Your browser does not support the video tag. ); }; [/code] Любая помощь будет оценена Подробнее здесь: [url]https://stackoverflow.com/questions/79762333/safari-fails-to-play-mp4-video-from-strapi-backend-works-in-chrome-cors-issues[/url]