无法在React Quill中播放视频

huangapple go评论62阅读模式
英文:

can't play video in react quill

问题

I can't play video in react quill when I set resize picture in react quill, every time I add a video it gets resized like a photo, and can't play. So does anyone have a way.

这是我的代码

type here
import React, { useState, useEffect } from "react";
import { useQuill } from "react-quilljs";
import "quill/dist/quill.snow.css";
import BlotFormatter from "quill-blot-formatter/dist/BlotFormatter";

function HtmlEditor() {
  
  // const { quill, quillRef } = useQuill();
  const { quill, quillRef, Quill } = useQuill({
    modules: { blotFormatter: {} },
  });
  if (Quill && !quill) {
    Quill.register("modules/blotFormatter", BlotFormatter);
  }
  //==========================================================

  const [value, setValue] = useState();

  //b2
  useEffect(() => {
    if (quill) {
      quill.on("text-change", (delta, oldContents) => {
        console.log(quillRef.current.firstChild.innerHTML);
        setValue(quillRef.current.firstChild.innerHTML);

        let currrentContents = quill.getContents();
        console.log(currrentContents.diff(oldContents));
      });
    }
  }, [quill, Quill]);

  // console.log(value);
  console.log(JSON.stringify(value));
  // console.log(quillRef);
  return (
    <div>
      <div className="mt-[50px] mx-auto " style={{ width: 1500, height: 1300 }}>
        <div ref={quillRef} />
      </div>
    </div>
  );
}
export default HtmlEditor;

谢谢你的帮助。

英文:

I can't play video in react quill when I set resize picture in react quill, every time I add a video it gets resized like a photo, and can't play. So does anyone have a way.

this is my code

type here
import React, { useState, useEffect } from &quot;react&quot;;
import { useQuill } from &quot;react-quilljs&quot;;
import &quot;quill/dist/quill.snow.css&quot;;
import BlotFormatter from &quot;quill-blot-formatter/dist/BlotFormatter&quot;;


function HtmlEditor() {
  
  // const { quill, quillRef } = useQuill();
  const { quill, quillRef, Quill } = useQuill({
    modules: { blotFormatter: {} },
  });
  if (Quill &amp;&amp; !quill) {
    Quill.register(&quot;modules/blotFormatter&quot;, BlotFormatter);
  }
  //==========================================================

  const [value, setValue] = useState();

  //b2
  useEffect(() =&gt; {
    if (quill) {
      quill.on(&quot;text-change&quot;, (delta, oldContents) =&gt; {
        console.log(quillRef.current.firstChild.innerHTML);
        setValue(quillRef.current.firstChild.innerHTML);

        let currrentContents = quill.getContents();
        console.log(currrentContents.diff(oldContents));
      });
    }
  }, [quill, Quill]);

  // console.log(value);
  console.log(JSON.stringify(value));
  // console.log(quillRef);
  return (
    &lt;div&gt;
      &lt;div className=&quot;mt-[50px] mx-auto &quot; style={{ width: 1500, height: 1300 }}&gt;
        &lt;div ref={quillRef} /&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  );
}
export default HtmlEditor;

Thank you for your help.

答案1

得分: 0

这是您提供的代码的中文翻译:

您可以考虑这段代码

import Quill from "quill";
import { Video } from "quill-video-resize";
import "quill-video-resize/dist/quill-video-resize.css";

Quill.register({ "formats/video": Video });

const { quill, quillRef } = useQuill({
  modules: {
    blotFormatter: {},
    toolbar: {
      container: "#toolbar",
      handlers: {
        // 这里是您的自定义处理程序
      },
    },
  },
});

quill.root.quill = quill;
quill.insertEmbed(index, "video", src, "user");
英文:

You can consider this code:

import Quill from &quot;quill&quot;;
import { Video } from &quot;quill-video-resize&quot;;
import &quot;quill-video-resize/dist/quill-video-resize.css&quot;;

Quill.register({ &quot;formats/video&quot;: Video });

const { quill, quillRef } = useQuill({
  modules: {
    blotFormatter: {},
    toolbar: {
      container: &quot;#toolbar&quot;,
      handlers: {
        // Your custom handlers here
      },
    },
  },
});

quill.root.quill = quill;
quill.insertEmbed(index, &quot;video&quot;, src, &quot;user&quot;);

huangapple
  • 本文由 发表于 2023年7月3日 10:57:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定