国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

react+video.js h5自定義視頻暫停圖標(biāo)

這篇具有很好參考價(jià)值的文章主要介紹了react+video.js h5自定義視頻暫停圖標(biāo)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

目錄

參考網(wǎng)址

效果圖,暫停時(shí)顯示暫停圖標(biāo),播放時(shí)隱藏暫停圖標(biāo)

代碼說明,代碼傳入url后,可直接復(fù)制使用

VideoPausedIcon.ts 組件

VideoCom.tsx

Video.module.less


參考網(wǎng)址

?在Video.js播放器中定制自己的組件 - acgtofe

效果圖,暫停時(shí)顯示暫停圖標(biāo),播放時(shí)隱藏暫停圖標(biāo)

react video自定義按鈕,前端庫--videojs,前端框架--react,前端框架

代碼說明,代碼傳入url后,可直接復(fù)制使用

注意:videojs升級(jí)后,不能用extend創(chuàng)建組件,需要按下方代碼建一個(gè)組件文章來源地址http://www.zghlxwxcb.cn/news/detail-788118.html

VideoPausedIcon.ts 組件
import videojs from "video.js";

const Component: any = videojs.getComponent("Component");

export class VideoPausedIcon extends Component {
  constructor(player: any, options: any) {
    super(player, options);
    // 監(jiān)聽,暫停播放,顯示播放按鈕
    player.on("pause", () => {
      this.visible = true;
      const el = this.el();
      el.className = "vjs-define-paused";
    });
    // 監(jiān)聽,開始播放,隱藏播放按鈕,通過videojs自帶的 vjs-hidden 類
    player.on("play", () => {
      this.visible = false;
      const el = this.el();
      el.className = "vjs-define-paused vjs-hidden";
    });
    this.on("touchstart", this.handleTouchStart);
    this.on("touchend", this.handleTouchEnd);
    // 如果需要在web端使用,必須,不兼容的話,web端點(diǎn)擊按鈕就不會(huì)暫停/播放
    this.on("click", (e: any) => this.handleClick(e, player));
  }

  createEl() {
    let pauseIcon = videojs.dom.createEl("div", {
      className: "vjs-define-paused",
      tabIndex: -1,
    });
    !this.visible && videojs.dom.appendContent(pauseIcon, "");
    return pauseIcon;
  }

  handleTouchStart(e: any) {
    // 此處必須,不然點(diǎn)擊按鈕不能播放/暫停
    e.stopPropagation();
  }

  handleTouchEnd(e: any) {
    // 此處必須,不然點(diǎn)擊按鈕不能播放/暫停
    e.stopPropagation();
  }

  handleClick(e: any, player: any) {
    e.stopPropagation();
    if (!player) {
      return;
    }
    const paused = player.paused();
    if (paused) {
      player.play();
    } else {
      player.pause();
    }
  }
}
VideoCom.tsx
import React, { useEffect } from "react";
import videojs from "video.js";
import "video.js/dist/video-js.css";
import styles from "./Video.module.less";
import { VideoPausedIcon } from "./VideoPausedIcon";

interface IProps {
  url: string;
}

const VideoCom: React.FC<IProps> = (props: any) => {
  const videoRef = React.useRef<any>(null);
  const playerRef = React.useRef<any>(null);

  useEffect(() => {
    const player: any = playerRef && playerRef.current;
    return () => {
      if (player && !player.isDisposed()) {
        player.dispose();
        playerRef.current = null;
      }
    };
  }, [playerRef]);

  useEffect(() => {
    if (!props.url) {
      return;
    }
    let options: any = {
      controlBar: {
        fullscreenToggle: true,
        pictureInPictureToggle: false,
        volumePanel: false,
        playToggle: false,
      },
      muted: false,
      controls: true, //進(jìn)度條
      autoplay: false, //自動(dòng)播放
      loop: false, //是否循環(huán)
      languages: {
        "zh-CN": new URL(`video.js/dist/lang/zh-CN.json`, import.meta.url).href,
      },
      language: "zh-CN",
      preload: "auto",
      nodownload: true,
      sources: [{ src: props.url, type: "video/mp4" }],
    };

    // Make sure Video.js player is only initialized once
    if (!playerRef || !playerRef.current) {
      // The Video.js player needs to be _inside_ the component el for React 18 Strict Mode.
      const videoElement = document.createElement("video-js");
      videoRef &&
        videoRef.current &&
        videoRef.current.appendChild(videoElement);

      playerRef.current = videojs(videoElement, options, () => {
        console.log("player is ready");
        const player: any = playerRef.current;
        player.on("error", (err: any) => {
          console.log("source load fail");
          // message.error("視頻源請(qǐng)求出錯(cuò)");
        });
        let touchStartTime = 0;
        let touchEndTime = 0;
        player.on("touchstart", (e: any) => {
          touchStartTime = new Date().getTime();
        });
        player.on("touchend", (e: any) => {
          touchEndTime = new Date().getTime();
          if (touchEndTime - touchStartTime < 300) {
            const paused = player.paused();
            if (paused) {
              player.play();
            } else {
              player.pause();
            }
          }
        });
      });
      createPausedIcon();
    } else {
      const player: any = playerRef.current;
      player.src(options.sources);
    }
  }, [
    props.url,
    playerRef,
    videoRef
  ]);

  const createPausedIcon = () => {
    const player = playerRef && playerRef.current;
    if (!player) {
      return;
    }
    const Component: any = videojs.getComponent("Component");
    Component.registerComponent("VideoPausedIcon", VideoPausedIcon);
    const options = {};
    const properIndex = player
      .children()
      .indexOf(player.getChild("BigPlayButton"));
    player.addChild("VideoPausedIcon", options, properIndex);
  };

  return (
    <div className={styles.container}>
      <div className={styles.videoBox} ref={videoRef}></div>
    </div>
  );
};

export default VideoCom;
Video.module.less
.container {
  width: 100%;
  height: 100%;

  .videoBox {
    width: 100%;
    height: 100%;

    :global {
      .video-js {
        width: 100%;
        height: 100%;

        .vjs-big-play-button {
          display: none;
        }

        .vjs-define-paused {
          width: 30px;
          height: 28px;
          background: rgba(43, 63, 46, 0.7);
          border: 1px solid rgb(0, 255, 140);
          border-radius: 10px;
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          transition: all .4s;

          &::after {
            display: block;
            content: '';
            position: absolute;
            top: 50%;
            left: calc(50% + 5px);
            transform: translate(-50%, -50%);
            border-top: 5px solid;
            border-bottom: 5px solid;
            border-left: 8px solid;
            border-right: 8px solid;
            border-color: transparent;
            border-left-color: rgb(0, 255, 140);
          }
        }
      }
    }
  }

}

到了這里,關(guān)于react+video.js h5自定義視頻暫停圖標(biāo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • React Swiper.js使用(詳細(xì)版)3D聚焦特效,自定義導(dǎo)航按鈕等

    共用代碼 普通版本 重點(diǎn):??modules={[Navigation, Pagination]}? ?Swiper, SwiperSlide? 沒什么好說的 自定義導(dǎo)航按鈕 / 進(jìn)度條 +?解決同一頁面,多個(gè)swiper.js 導(dǎo)航切換按鈕沖突問題 這里的重點(diǎn)是:? 1、 通過直接引入less文件?重新定義 swiper-button-prev等類 或 :global ,自定義導(dǎo)航按鈕 / 進(jìn)

    2024年02月07日
    瀏覽(15)
  • React學(xué)習(xí)筆記(番外一)——video.js視頻播放組件的入門及排坑經(jīng)歷

    React學(xué)習(xí)筆記(番外一)——video.js視頻播放組件的入門及排坑經(jīng)歷

    很久沒有靜下心寫博客了。近段時(shí)間接到一個(gè)任務(wù),前端頁面要加上視頻播放功能。實(shí)現(xiàn)加排坑前后花了三天時(shí)間(別問我問什么這么久??),覺得還是有必要記錄一下的。 這一部分有必要寫在最前面,避免你看了一長串安裝、引入、代碼,然后發(fā)現(xiàn)自己想要播放的視頻格

    2024年02月02日
    瀏覽(27)
  • js前端獲取video視頻名稱+時(shí)長+縮略圖+寬高

    js前端獲取video視頻名稱+時(shí)長+縮略圖+寬高,縮略圖的核心是用canvas畫出來的base64圖片,調(diào)用函數(shù)需要傳入二進(jìn)制的視頻文件,注意這是一個(gè)promise函數(shù),需要用then來接收,代碼如下

    2024年02月12日
    瀏覽(24)
  • video.js 視頻截圖、錄制、自定義全屏,hls、flv、mp4視頻播放

    video.js 視頻截圖、錄制、自定義全屏,hls、flv、mp4視頻播放

    功能 video.js內(nèi)嵌 截圖、錄制功能 (圖片、視頻會(huì)下載到本地) 自定義全屏 播放hls、flv、mp4 功能集合成Vue組件 參考 video.js components RecordRTC demo video 截圖并下載 video.js添加自定義組件的方法 使用RecordRTC對(duì)video視頻進(jìn)行錄制 播放hls、flv、mp4 安裝 引入 html 引入組件(視頻地址使

    2023年04月08日
    瀏覽(26)
  • vue 項(xiàng)目中使用video實(shí)現(xiàn)視頻播放效果暫停播放(多個(gè)視頻)

    根據(jù)ref判斷是否暫停狀態(tài)返回 true false vue 控制video視頻的播放暫停(多個(gè)視頻) 安裝video.js 在main.js中引用 頁面

    2024年02月11日
    瀏覽(19)
  • video全屏操作欄自定義樣式&&js 指定元素全屏&&視頻截圖下載

    video全屏操作欄自定義樣式&&js 指定元素全屏&&視頻截圖下載

    目錄 1. 頁面結(jié)構(gòu) 2. 全屏方法 3. 截圖方法 4. 樣式代碼 5. 效果截圖 6. 附上完整代碼 最近遇到的需求就是重新video標(biāo)簽的控制欄的樣式,包括進(jìn)度條、音量、倍速、全屏等樣式,在正常狀態(tài)下,可以將原生樣式隱藏掉自定義新的控制欄元素定位上去,但是全屏后樣式失效,出現(xiàn)

    2024年02月12日
    瀏覽(19)
  • Unity點(diǎn)擊按鈕控制視頻播放和暫停

    省流:整體腳本放在底部,需要可直接到底部 1、導(dǎo)入命名空間 2、創(chuàng)建變量 3、第一幀開始時(shí)調(diào)用 4、每幀調(diào)用 5、定義方法OnplayorpauseVideo 6、創(chuàng)建圖像,添加視頻播放器(Video Player)組件,把腳本放到圖像,把按鈕添加到腳本。 完整代碼

    2024年02月03日
    瀏覽(19)
  • 微信小程序 video 組件[播新視頻舊視頻暫停,再次播放延續(xù)上次播放時(shí)長]

    微信小程序 video 組件[播新視頻舊視頻暫停,再次播放延續(xù)上次播放時(shí)長]

    1、引言 微信官方文檔網(wǎng)址:媒體組件 / video (qq.com) 2、播新視頻舊視頻暫停 ? 問題:?多個(gè)視頻同時(shí)播放的問題 需求: ????????1.?在點(diǎn)擊播放的事件中需要找到上一個(gè)播放的視頻 ????????2.?在播放新的視頻之前關(guān)閉上一個(gè)正在播放的視頻 關(guān)鍵: ????????1.?如何

    2024年02月19日
    瀏覽(85)
  • uniapp實(shí)現(xiàn)視頻上下滑動(dòng)功能(小程序)以及video組件的暫停和播放

    uni推薦使用swiper組件實(shí)現(xiàn),在video組件的下面介紹有寫。 這里實(shí)現(xiàn)方式是: 父組件先用swiper組件實(shí)現(xiàn)縱向滑動(dòng),然后在每個(gè)swiper-item中插入視屏組件video-item-vx(自己定義的組件),在video-item-vx組件中實(shí)現(xiàn)視屏播放,具體別的細(xì)節(jié)根據(jù)需要自己實(shí)現(xiàn)。 注意:不能無限添加swi

    2023年04月22日
    瀏覽(86)
  • 前端Vue自定義輪播圖視頻播放組件 仿京東商品詳情輪播圖視頻Video播放效果 可圖片預(yù)覽

    前端Vue自定義輪播圖視頻播放組件 仿京東商品詳情輪播圖視頻Video播放效果 可圖片預(yù)覽

    隨著技術(shù)的發(fā)展,開發(fā)的復(fù)雜度也越來越高,傳統(tǒng)開發(fā)方式將一個(gè)系統(tǒng)做成了整塊應(yīng)用,經(jīng)常出現(xiàn)的情況就是一個(gè)小小的改動(dòng)或者一個(gè)小功能的增加可能會(huì)引起整體邏輯的修改,造成牽一發(fā)而動(dòng)全身。通過組件化開發(fā),可以有效實(shí)現(xiàn)單獨(dú)開發(fā),單獨(dú)維護(hù),而且他們之間可以隨

    2024年02月15日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包