react video player code example
Example 1: react player disable download
<ReactPlayer
url={[{src: Video, type: 'video/mp4'}]}
controls
width='100%'
height='100%'
config={{ file: {
attributes: {
controlsList: 'nodownload'
}
}}}
onEnded={()=>this.onEnded()}
/>
Example 2: html5 video player
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag. <!-- Text to be shown incase browser doesnt support html5 -->
</video>
Example 3: react video srcObject
playTrack(track) {
const stream = new MediaStream()
stream.addTrack(track)
this.audio.srcObject = stream;
}
render() {
return (
<audio ref={audio => {this.audio = audio}} controls volume="true" autoPlay />
)
}
Example 4: react responsive video player
class ResponsivePlayer extends Component {
render () {
return (
<div className='player-wrapper'>
<ReactPlayer
className='react-player'
url='https://www.youtube.com/watch?v=ysz5S6PUM-U'
width='100%'
height='100%'
/>
</div>
)
}
}
Example 5: react audio player
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import ReactAudioPlayer from '../src/index.tsx';
describe('ReactAudioPlayer', function() {
const song = './fixtures/turkish_march.ogg';
test('renders an audio element', function() {
const instance = ReactTestUtils.renderIntoDocument(
<ReactAudioPlayer />
);
const instanceEl = ReactDOM.findDOMNode(instance);
expect(instanceEl.tagName).toBe('AUDIO');
});
test('sets the loop attribute if provided', function() {
const instance = ReactTestUtils.renderIntoDocument(
<ReactAudioPlayer
src={song}
loop
/>
);
const instanceEl = ReactDOM.findDOMNode(instance);
expect(instanceEl.getAttribute('loop')).not.toBe(null);
})
test('sets title', function() {
const instance = ReactTestUtils.renderIntoDocument(
<ReactAudioPlayer
src={song}
title="Turkish march"
/>
);
const instanceEl = ReactDOM.findDOMNode(instance);
expect(instanceEl.getAttribute("title")).toBe("Turkish march");
})
test('receives all custom props', function() {
const instance = ReactTestUtils.renderIntoDocument(
<ReactAudioPlayer
src={song}
name="custom-name"
data-id="custom-data"
controlsList="nodownload"
/>
);
const props = Object.keys(instance.props);
expect(props).toContain('name');
expect(props).toContain('data-id');
expect(props).toContain('controlsList');
});
});