support deal stream media for the componet of nplayer-react #457
Open
haianweifeng wants to merge 4 commits intooyuyue:mainfrom
Open
support deal stream media for the componet of nplayer-react #457haianweifeng wants to merge 4 commits intooyuyue:mainfrom
haianweifeng wants to merge 4 commits intooyuyue:mainfrom
Conversation
Owner
|
非常感谢您提交 pr。 不过这个 是否有一些场景必须使用 下面是 code sandbox 里面的 react 例子代码, import { useEffect, useRef } from "react";
import NPlayer from "@nplayer/react";
import "./styles.css";
export default function App() {
const player = useRef();
useEffect(() => {
console.log(player.current);
}, []);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<NPlayer
ref={player}
options={{ src: "https://v-cdn.zjol.com.cn/280443.mp4" }}
/>
</div>
);
} |
|
但是,到底如何用 react 组件加载 m3u8 流文件? 尝试了各种方法均失败,能给一个例子或示例代码吗? |
Author
import { useEffect, useRef } from "react";
import NPlayer from "@nplayer/react";
import Hls from 'hls.js';
import "./styles.css";
export default function App() {
const player = useRef();
useEffect(() => {
console.log(player.current);
const hls = new Hls();
hls.attachMedia(player.current.video);
hls.on(Hls.Events.MEDIA_ATTACHED, () => {
hls.loadSource('https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8');
});
}, []);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<NPlayer
ref={player}
options={{ src: "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8" }}
/>
</div>
);
} |
It works. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.