about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/audio
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-07-15 16:56:33 +0200
committerGitHub <noreply@github.com>2020-07-15 16:56:33 +0200
commit37c092e9fdedd36c167e4b84610e7346c446e1d3 (patch)
tree88992f2d65c83ece4e93f0b4b5c34ffed0989138 /app/javascript/flavours/glitch/features/audio
parent7a23347db5be3f262dbcafbecf768588dc648bda (diff)
parent470458da13586db0e6ca074987fecfc80293d955 (diff)
Merge pull request #1382 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours/glitch/features/audio')
-rw-r--r--app/javascript/flavours/glitch/features/audio/index.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/features/audio/index.js b/app/javascript/flavours/glitch/features/audio/index.js
index 120a5ce1a..9cb2307fd 100644
--- a/app/javascript/flavours/glitch/features/audio/index.js
+++ b/app/javascript/flavours/glitch/features/audio/index.js
@@ -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'
         />