[Glitch] Fix audio and video items in account gallery in web UI

Port 6cc5b822f5 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
This commit is contained in:
Eugen Rochko
2020-07-10 22:09:28 +02:00
committed by Thibaut Girka
parent 3f60b096b5
commit dad3132046
5 changed files with 77 additions and 46 deletions

View File

@@ -37,6 +37,7 @@ class Audio extends React.PureComponent {
backgroundColor: PropTypes.string,
foregroundColor: PropTypes.string,
accentColor: PropTypes.string,
autoPlay: PropTypes.bool,
};
state = {
@@ -244,6 +245,14 @@ class Audio extends React.PureComponent {
this.setState({ hovered: false });
}
handleLoadedData = () => {
const { autoPlay } = this.props;
if (autoPlay) {
this.audio.play();
}
}
_initAudioContext () {
const context = new AudioContext();
const source = context.createMediaElementSource(this.audio);
@@ -321,7 +330,7 @@ class Audio extends React.PureComponent {
}
render () {
const { src, intl, alt, editable } = this.props;
const { src, intl, alt, editable, autoPlay } = this.props;
const { paused, muted, volume, currentTime, duration, buffer, dragging } = this.state;
const progress = (currentTime / duration) * 100;
@@ -330,10 +339,11 @@ class Audio extends React.PureComponent {
<audio
src={src}
ref={this.setAudioRef}
preload='none'
preload={autoPlay ? 'auto' : 'none'}
onPlay={this.handlePlay}
onPause={this.handlePause}
onProgress={this.handleProgress}
onLoadedData={this.handleLoadedData}
crossOrigin='anonymous'
/>