Giter Site home page Giter Site logo

React control? about wfplayer HOT 4 CLOSED

zhw2590582 avatar zhw2590582 commented on June 19, 2024
React control?

from wfplayer.

Comments (4)

zhw2590582 avatar zhw2590582 commented on June 19, 2024
import React, { useEffect, useState } from "react";
import WFPlayer from "wfplayer";

export default () => {
  const [waveform, setWaveform] = useState(null);
  const $waveform = React.createRef();
  const $video = React.createRef();

  useEffect(() => {
    const waveform = new WFPlayer({
      container: $waveform.current,
      mediaElement: $video.current,
    });

    setWaveform(waveform);
  }, []);

  return (
    <div>
      <video src="test.mp4" ref={$video} />
      <div ref={$waveform} />
    </div>
  );
};

from wfplayer.

larrywal avatar larrywal commented on June 19, 2024

Lol - thanks :). This would clean up much of what I had done. Although...

  1. I'm using it for audio and the file path needs to be dynamic, so I'm assuming I'd update the 3rd line (export default) to include a path parameter and pass to video src? And obviously I'd make the video tag an audio tag...

  2. This wrapping doesn't make it obvious how I'd use the rest of the WFPlayer controls - e.g. the events, etc.. seek, setOptions, adding click handlers, etc... Seems like that wouldn't really work unless waveform is exposed externally, and then it gets messy, no?

from wfplayer.

zhw2590582 avatar zhw2590582 commented on June 19, 2024

If your file path is dynamic, it is recommended to destroy the waveform and re instantiate it every time the path changes

from wfplayer.

larrywal avatar larrywal commented on June 19, 2024

Thanks - that helps...although...I'm new to React...not sure how I would do that, right? Because React controls the lifecycle of the included component you created above that I would be including into my page?

from wfplayer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.