第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Vimeo,檢測(cè)全屏以阻止獲取新播放器(動(dòng)態(tài)寬度變化)

Vimeo,檢測(cè)全屏以阻止獲取新播放器(動(dòng)態(tài)寬度變化)

炎炎設(shè)計(jì) 2023-10-17 17:03:51
我想動(dòng)態(tài)更改 vimeo 播放器的寬度以適應(yīng)窗口寬度。您可以在問題末尾看到組件的完整代碼,也許已經(jīng)有一種更簡(jiǎn)單的方法來動(dòng)態(tài)更改播放器的寬度,所以我根本不必處理這些問題(提供的響應(yīng)選項(xiàng)) by vimeo 對(duì)我不起作用)。我當(dāng)前解決方案遇到的問題:如果播放器進(jìn)入全屏或在全屏上旋轉(zhuǎn)手機(jī),我不想觸發(fā)更改,因?yàn)?vimeo 已經(jīng)自動(dòng)處理這些更改,但我很難檢測(cè)播放器是否在全屏顯示。    const isFullscreen = (document.fullscreenElement       || document.webkitFullscreenElement       || document.mozFullScreenElement       || document.msFullscreenElement       || playerWidth === delayedWidth)此解決方案不適用于 iphone 11 pro 以及可能所有 Safari 瀏覽器,因?yàn)槿凉δ懿⑽赐耆珜?shí)現(xiàn)。
查看完整描述

2 回答

?
POPMUISE

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊

我正在使用 u-wave vimeo 播放器,其中響應(yīng)已得到照顧。


import Vimeo from '@u-wave/react-vimeo';`


<Vimeo

    video={videoURL}

    autoplay={false}

    controls={true}

    responsive={true}

    onEnd={() => { onVideoEnd() }}

    style={{ justifyContent: 'center'}}

    start={0}

    onTimeUpdate={(duration) => { console.log(duration }} />


查看完整回答
反對(duì) 回復(fù) 2023-10-17
?
翻翻過去那場(chǎng)雪

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊

如果您遇到類似問題,請(qǐng)查看更新的 @vimeo/player 文檔: https: //www.npmjs.com/package/@vimeo/player#getfullscreen-promiseboolean-error


我更新和測(cè)試的代碼如下所示:


import React, {

  useEffect, useContext, useState, useRef,

} from 'react';

import PropTypes from 'prop-types';

import Player from '@vimeo/player';


import { BrowserContext } from '../../contexts/BrowserContext';


const TAG = 'player';


/**

 * remove event listeners

 * @param {object} player

 */

function removeEventListeners(player) {

  if (!player) return;

  player.off('ended');

  player.off('pause');

  player.off('play');

}

/**

 * remove interval

 * @param {number} interval

 */

function removeInterval(interval) {

  console.tag(TAG).debug('removeInterval called');

  window.clearInterval(interval);

}


/**

 * 640×480, 800×600, 960×720, 1024×768, 1280×960,

 * 1400×1050, 1440×1080 , 1600×1200, 1856×1392, 1920×1440, and 2048×1536

 * @param {number} width

 */

function computeRatio(delayedWidth, percentage = 0.9) {

  const height = window.innerHeight;

  const width = delayedWidth - (delayedWidth * (1 - percentage));


  if (height <= 480) {

    return width > 640 ? 640 : width;

  }

  if (height <= 600) {

    return width > 800 ? 800 : width;

  }

  if (height <= 720) {

    return width > 960 ? 960 : width;

  }

  if (height <= 768) {

    return width > 1024 ? 1024 : width;

  }

  if (height <= 960) {

    return width > 1280 ? 1280 : width;

  }

  if (height <= 1050) {

    return width > 1400 ? 1400 : width;

  }

  if (height <= 1080) {

    return width > 1440 ? 1440 : width;

  }

  if (height <= 1200) {

    return width > 1600 ? 1600 : width;

  }

  if (height <= 1392) {

    return width > 1856 ? 1856 : width;

  }

  if (height <= 1440) {

    return width > 1920 ? 1920 : width;

  }

  if (height <= 1536) {

    return width > 2048 ? 2048 : width;

  }

  return width;

}


const VideoPlayer = ({

  index, link, onProgress, latestProgress, widthPercentage, onVideoEnded,

}) => {

  const { delayedWidth } = useContext(BrowserContext);

  const [progress, setProgress] = useState(latestProgress < 1 ? latestProgress : 0);

  const playerRef = useRef(null);

  const intervalRef = useRef(null);


  useEffect(() => {

    console.tag(TAG).debug('changing delayed width', delayedWidth);


    const asyncEffect = async () => {

      const player = playerRef.current;

      if (player) {

        console.tag(TAG).debug('player detected, checking fullscreen');

        const isFullscreen = await player.getFullscreen();

        console.tag(TAG).debug('fullscreen detected', isFullscreen);


        if (isFullscreen) {

          return;

        }


        removeEventListeners(player);

        playerRef.current = null;

        player.pause(); // gets rid of interval

        player.destroy();

      }


      const options = { id: link, width: computeRatio(delayedWidth, widthPercentage) };

      const newPlayer = new Player(`frame-${index}`, options);

      playerRef.current = newPlayer;


      if (progress) {

        newPlayer.getDuration().then((duration) => {

          const seconds = duration * progress;

          newPlayer.setCurrentTime(seconds);

        });

      }


      const keepTrackProgress = async () => {

        // gets duration of video in seconds

        const duration = await newPlayer.getDuration();


        intervalRef.current = window.setInterval(() => {

          const currentPlayer = playerRef.current;

          if (!currentPlayer) {

            return;

          }

          currentPlayer.getCurrentTime().then((seconds) => {

            // `seconds` indicates the current playback position of the video

            const newProgress = seconds / duration;

            console.tag(TAG).debug(`progress: ${newProgress}, duration ${duration}, seconds ${seconds}`);

            onProgress(newProgress);

            setProgress(newProgress);

          });

          // track every next 10 seconds of progress

        }, 10000);

      };


      newPlayer.on('ended', () => {

        console.tag(TAG).debug('player onEnded');

        removeInterval(intervalRef.current);

        intervalRef.current = null;

        onProgress(1);

        setProgress(1);

        onVideoEnded();

      });


      newPlayer.on('pause', ({ duration, seconds }) => {

        console.tag(TAG).debug('player onPause');

        removeInterval(intervalRef.current);

        intervalRef.current = null;

        const newProgress = seconds / duration;

        console.tag(TAG).debug(`progress at paused: ${newProgress}, duration ${duration}, seconds ${seconds}`);

        onProgress(newProgress);

        setProgress(newProgress);

      });


      newPlayer.on('play', () => {

        console.tag(TAG).debug('player onPlay');

        keepTrackProgress();

      });

    };


    asyncEffect();

  }, [delayedWidth]);


  useEffect(() => () => {

    removeInterval(intervalRef.current);

    removeEventListeners(playerRef.current);

    if (playerRef.current) {

      playerRef.current.destroy();

    }

  }, []);


  return (

    <div id={`frame-${index}`} className="frame-wrapper" />

  );

};



VideoPlayer.propTypes = {

  index: PropTypes.number.isRequired,

  link: PropTypes.string.isRequired,

  onProgress: PropTypes.func.isRequired,

  onVideoEnded: PropTypes.func,

  latestProgress: PropTypes.number.isRequired,

  widthPercentage: PropTypes.number,

};


VideoPlayer.defaultProps = {

  widthPercentage: 0.9,

  onVideoEnded: () => {},

};


export default VideoPlayer;



查看完整回答
反對(duì) 回復(fù) 2023-10-17
  • 2 回答
  • 0 關(guān)注
  • 136 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)