Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dashSource component for an dash player integration #275

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions docs/lib/Customize/CustomizeSourcePage.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React from 'react';
import { PrismCode } from 'react-prism';
import { Button } from 'reactstrap';
import Helmet from 'react-helmet';
import CustomizeSourceExample from '../examples/CustomizeSource';
const CustomizeSourceExampleSource = require('!!raw-loader!../examples/CustomizeSource');
import CustomizeDashSourceExample from '../examples/CustomizeDashSource';

const CustomizeSourceHLSSource = require('!!raw-loader!../examples/CustomizeSource');
const CustomizeSourceDashSource = require('!!raw-loader!../examples/CustomizeDashSource');
const HLSSourceSource = require('!!raw-loader!../examples/HLSSource');
const DashSource = require('!!raw-loader!../examples/DashSource');

export default class CustomizeSourcePage extends React.Component {
render() {
return (
<div>
<Helmet title="CustomizeSource" />
<h3>Customize Video Source</h3>
<p>This is an example on how to customize a HLS video source.</p>
<div className="docs-example">
<CustomizeSourceExample />
</div>
<p />
<h4>HLSSource Component</h4>
<pre>
<PrismCode className="language-jsx">{HLSSourceSource}</PrismCode>
</pre>
<h4>Customize Source Example</h4>
<pre>
<PrismCode className="language-jsx">
{CustomizeSourceExampleSource}
</PrismCode>
</pre>
</div>
);
}
render() {
return (
<div>
<Helmet title="CustomizeSource" />
<h3>Customize Video Source</h3>
<p>This is an example on how to customize a HLS video source.</p>
<div className="docs-example">
<CustomizeSourceExample />
</div>
<p />
<h4>HLSSource Component</h4>
<pre>
<PrismCode className="language-jsx">{HLSSourceSource}</PrismCode>
</pre>
<h4>Customize HLS Source Example</h4>
<pre>
<PrismCode className="language-jsx">
{CustomizeSourceHLSSource}
</PrismCode>
</pre>
<p>This is an example on how to customize a Dash video source.</p>
<div className="docs-example">
<CustomizeDashSourceExample />
</div>
<p />
<h4>DashSource Component</h4>
<pre>
<PrismCode className="language-jsx">{DashSource}</PrismCode>
</pre>
<h4>Customize Dash Source Example</h4>
<pre>
<PrismCode className="language-jsx">
{CustomizeSourceDashSource}
</PrismCode>
</pre>
</div>
);
}
}
25 changes: 25 additions & 0 deletions docs/lib/examples/CustomizeDashSource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { Player } from 'video-react';
import DashSource from "./DashSource";

export default props => {
// Add customized HLSSource component into video-react Player
mondaychen marked this conversation as resolved.
Show resolved Hide resolved
// 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
mondaychen marked this conversation as resolved.
Show resolved Hide resolved

const handleDashPlayer = (dash) => {
// Use methods form dash.js to customise dashSource
dash.setFastSwitchEnabled(true);
mondaychen marked this conversation as resolved.
Show resolved Hide resolved
};

return (
<Player>
<DashSource
isVideoChild
src="http://dash.edgesuite.net/akamai/bbb_30fps/bbb_30fps.mpd"
handleDashPlayer={handleDashPlayer}
/>
</Player>
);
};
58 changes: 58 additions & 0 deletions docs/lib/examples/DashSource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { Component } from 'react';
import dashjs from 'dashjs';

const DASH_EXTENSIONS = /\.(mpd)($|\?)/i;
export const checkDash = src => DASH_EXTENSIONS.test(src);

export default class DashSource extends Component {
constructor(props, context) {
super(props, context);
this.state = {
type: 'video/mp4',
};
this.load = this.load.bind(this);
this.dash = dashjs.MediaPlayer().create();
}

componentDidMount() {
this.load();
}

componentDidUpdate(prevProps) {
if (prevProps.src !== this.props.src) {
this.load();
}
}

componentWillUnmount() {
// destroy dash video source
this.props.video.removeAttribute('src');
}

load() {
const {
src, video, playing, handleDashPlayer,
} = this.props;
// load dash video source base on dash.js
if (checkDash(src)) {
this.setState({
type: 'application/x-mpegURL',
});
this.dash.initialize(video, src, playing);
this.dash.getDebug().setLogToBrowserConsole(false);
this.dash.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, () => {
handleDashPlayer(this.dash);
this.dash.setFastSwitchEnabled(true);
});
}
}

render() {
return (
<source
src={this.props.src}
type={this.state.type}
/>
);
}
}
Loading