I want to play video from one of the url by streaming in reactjs does this supports Video-React could someone help me out.
Asked
Active
Viewed 8,843 times
1 Answers
3
Yes! In their documentation here you can see them creating a source using HLS streaming:
import React, { Component } from 'react';
import Hls from 'hls.js';
export default class HLSSource extends Component {
constructor(props, context) {
super(props, context);
this.hls = new Hls();
}
componentDidMount() {
// `src` is the property get from this component
// `video` is the property insert from `Video` component
// `video` is the html5 video element
const { src, video } = this.props;
// load hls video source base on hls.js
if (Hls.isSupported()) {
this.hls.loadSource(src);
this.hls.attachMedia(video);
this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
video.play();
});
}
}
componentWillUnmount() {
// destroy hls video source
if (this.hls) {
this.hls.destroy();
}
}
render() {
return (
<source
src={this.props.src}
type={this.props.type || 'application/x-mpegURL'}
/>
);
}
}
And use it in your code:
import React from 'react';
import { Player } from 'video-react';
import HLSSource from './HLSSource';
export default (props) => {
// Add customized HLSSource component into video-react Player
// The Component with `isVideoChild` attribute will be added into video` component
// Please use this url if you test it from local:
// http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8
return (
<Player>
<HLSSource
isVideoChild
src="//d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8"
/>
</Player>
);
};

Stanley De Boer
- 4,921
- 1
- 23
- 31

Blue
- 22,608
- 7
- 62
- 92
-
Thank you @FrankerZ i will check same if anything else i will getback. – Sravan Shetty Oct 25 '18 at 13:23
-
tried this but get a loading screen loop. even on their demo it loops loading, same with the issue here https://github.com/video-react/video-react/issues/167 and https://codesandbox.io/s/l2k5ql01ol – MadeByDouglas Aug 09 '19 at 22:01
-
you are using the .mp4 format. So forget that and add .m3u8 format videos.(on this URL: https://codesandbox.io/s/l2k5ql01ol?file=/Player.js) – Athif Saheer Mar 16 '22 at 06:59