Skip to content
Snippets Groups Projects
Commit e9d4bece authored by Jack Reed's avatar Jack Reed Committed by Chris Beer
Browse files

Basic support for subtitles/captions

parent bbe724b7
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,7 @@ export class VideoViewer extends Component { ...@@ -6,8 +6,7 @@ export class VideoViewer extends Component {
/* eslint-disable jsx-a11y/media-has-caption */ /* eslint-disable jsx-a11y/media-has-caption */
/** */ /** */
render() { render() {
const { classes, videoResources } = this.props; const { captions, classes, videoResources } = this.props;
return ( return (
<div className={classes.container}> <div className={classes.container}>
<video controls className={classes.video}> <video controls className={classes.video}>
...@@ -16,6 +15,11 @@ export class VideoViewer extends Component { ...@@ -16,6 +15,11 @@ export class VideoViewer extends Component {
<source src={video.id} type={video.getFormat()} /> <source src={video.id} type={video.getFormat()} />
</Fragment> </Fragment>
))} ))}
{captions.map(caption => (
<Fragment key={caption.id}>
<track src={caption.id} label={caption.getLabel()} srcLang={caption.getProperty('language')} />
</Fragment>
))}
</video> </video>
</div> </div>
); );
...@@ -24,10 +28,12 @@ export class VideoViewer extends Component { ...@@ -24,10 +28,12 @@ export class VideoViewer extends Component {
} }
VideoViewer.propTypes = { VideoViewer.propTypes = {
captions: PropTypes.arrayOf(PropTypes.object),
classes: PropTypes.objectOf(PropTypes.string).isRequired, classes: PropTypes.objectOf(PropTypes.string).isRequired,
videoResources: PropTypes.arrayOf(PropTypes.object), videoResources: PropTypes.arrayOf(PropTypes.object),
}; };
VideoViewer.defaultProps = { VideoViewer.defaultProps = {
captions: [],
videoResources: [], videoResources: [],
}; };
...@@ -4,11 +4,12 @@ import { withTranslation } from 'react-i18next'; ...@@ -4,11 +4,12 @@ import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core'; import { withStyles } from '@material-ui/core';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import { VideoViewer } from '../components/VideoViewer'; import { VideoViewer } from '../components/VideoViewer';
import { getVisibleCanvasVideoResources } from '../state/selectors'; import { getVisibleCanvasCaptions, getVisibleCanvasVideoResources } from '../state/selectors';
/** */ /** */
const mapStateToProps = (state, { windowId }) => ( const mapStateToProps = (state, { windowId }) => (
{ {
captions: getVisibleCanvasCaptions(state, { windowId }) || [],
videoResources: getVisibleCanvasVideoResources(state, { windowId }) || [], videoResources: getVisibleCanvasVideoResources(state, { windowId }) || [],
} }
); );
......
...@@ -99,6 +99,15 @@ export default class MiradorCanvas { ...@@ -99,6 +99,15 @@ export default class MiradorCanvas {
return flatten(resources.filter((resource) => resource.getProperty('type') === 'Sound')); return flatten(resources.filter((resource) => resource.getProperty('type') === 'Sound'));
} }
/** */
get vttContent() {
const resources = flattenDeep([
this.canvas.getContent().map(i => i.getBody()),
]);
return flatten(resources.filter((resource) => resource.getProperty('format') === 'text/vtt'));
}
/** */ /** */
get resourceAnnotations() { get resourceAnnotations() {
return flattenDeep([ return flattenDeep([
......
...@@ -192,6 +192,14 @@ export const getVisibleCanvasVideoResources = createSelector( ...@@ -192,6 +192,14 @@ export const getVisibleCanvasVideoResources = createSelector(
.map(canvas => new MiradorCanvas(canvas).videoResources)), .map(canvas => new MiradorCanvas(canvas).videoResources)),
); );
export const getVisibleCanvasCaptions = createSelector(
[
getVisibleCanvases,
],
canvases => flatten(canvases
.map(canvas => new MiradorCanvas(canvas).vttContent)),
);
export const getVisibleCanvasAudioResources = createSelector( export const getVisibleCanvasAudioResources = createSelector(
[ [
getVisibleCanvases, getVisibleCanvases,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment