adding audio controls

This commit is contained in:
Roland Osborne 2022-05-04 22:39:58 -07:00
parent be9f143df0
commit f3c1bbf54f
3 changed files with 33 additions and 9 deletions

View File

@ -70,10 +70,10 @@ export function AddTopic() {
return <img style={{ height: '100%', objectFit: 'contain' }} src={item.url} alt="" />
}
if (item.audio) {
return <ReactPlayer height="100%" width="auto" url={item.url} />
return <ReactPlayer controls="true" height="100%" width="auto" url={item.url} />
}
if (item.video) {
return <ReactPlayer height="100%" width="auto" url={item.url} />
return <ReactPlayer controls="true" height="100%" width="auto" url={item.url} />
}
return <></>
}

View File

@ -2,22 +2,41 @@ import React, { useEffect, useState } from 'react';
import { Button } from 'antd';
import ReactPlayer from 'react-player'
import ReactResizeDetector from 'react-resize-detector';
import { SoundOutlined } from '@ant-design/icons';
import { PlayCircleOutlined, PauseCircleOutlined, SoundOutlined } from '@ant-design/icons';
import { AudioAssetWrapper } from './AudioAsset.styled';
export function AudioAsset({ label, audioUrl }) {
const [active, setActive] = useState(false);
const [dimension, setDimension] = useState({});
const [playing, setPlaying] = useState(false);
const [playing, setPlaying] = useState(true);
const [ready, setReady] = useState(false);
useEffect(() => {
setActive(false);
setPlaying(false);
setPlaying(true);
}, [label, audioUrl]);
const onReady = () => {
setPlaying(true);
setReady(true);
}
const Control = () => {
if (!ready) {
return <></>
}
if (playing) {
return (
<div onClick={() => setPlaying(false)}>
<PauseCircleOutlined style={{ fontSize: 48, color: '#eeeeee', cursor: 'pointer' }} />
</div>
)
}
return (
<div onClick={() => setPlaying(true)}>
<PlayCircleOutlined style={{ fontSize: 48, color: '#eeeeee', cursor: 'pointer' }} />
</div>
)
}
const Player = () => {
@ -28,7 +47,12 @@ export function AudioAsset({ label, audioUrl }) {
</div>
)
}
return <ReactPlayer style={{ visibility: 'hidden' }} playing={playing} height="100%" width="100%" controls="true" url={audioUrl} onReady={onReady} />
return (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<Control />
<ReactPlayer style={{ position: 'absolute', top: 0, visibility: 'hidden' }} playing={playing} height="100%" width="100%" controls="true" url={audioUrl} onReady={onReady} />
</div>
)
}
return (
@ -38,7 +62,7 @@ export function AudioAsset({ label, audioUrl }) {
if (height != dimension.height) {
setDimension({ height });
}
return <div style={{ height: '100%', width: dimension.height, backgroundColor: 'black' }} />
return <div style={{ height: '100%', width: dimension.height, backgroundColor: '#444444' }} />
}}
</ReactResizeDetector>
<div class="player" style={{ width: dimension.height, height: dimension.height }}>

View File

@ -67,7 +67,7 @@ export function useTopicItem(topic) {
const actions = {
getAssetUrl: (assetId) => {
return conversation.actions.getAssetUrl(topic.id, assetId);
return conversation.actions.getAssetUrl(topic?.id, assetId);
}
};