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