-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Fix issue with playing audio in Audio Explorer
- Created reusable `AudioPlayer` component with native audio tag - Fixed `AudioBox` component issues (Explorers) - Replaced 'material-ui-audio-player' component with `AudioPlayer` component (Explorers)
- Loading branch information
1 parent
e769435
commit 6692831
Showing
15 changed files
with
500 additions
and
481 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/aimcore/web/ui/src/components/AudioPlayer/AudioPlayer.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
export interface AudioPlayerProps extends React.HTMLProps<HTMLAudioElement> { | ||
audioRef: React.MutableRefObject<HTMLMediaElement | null>; | ||
src: string; | ||
isPlaying: boolean; | ||
processing: boolean; | ||
onDownload?: () => void; | ||
caption?: string; | ||
readyToPlay: boolean; | ||
onEnded: () => void; | ||
onCanPlay: () => void; | ||
onPlay: () => void; | ||
onPause: () => void; | ||
} |
58 changes: 58 additions & 0 deletions
58
src/aimcore/web/ui/src/components/AudioPlayer/AudioPlayer.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@use 'src/styles/abstracts' as *; | ||
|
||
.AudioPlayer { | ||
max-width: toRem(268px); | ||
&__controllers { | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
padding: $space-xs; | ||
background-color: $pico-5; | ||
border-radius: $border-radius-main; | ||
width: toRem(268px); | ||
height: toRem(40px); | ||
&__download { | ||
min-width: 1.5rem; | ||
} | ||
&__player { | ||
min-width: 1.5rem; | ||
height: 1.5rem; | ||
border-radius: $radius-main; | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
transition: background-color 0.18s ease-out; | ||
&:hover { | ||
background-color: rgba(28, 40, 82, 0.04); | ||
} | ||
.Icon__container { | ||
position: absolute; | ||
z-index: 0; | ||
font-size: $text-sm; | ||
} | ||
.MuiPaper-root { | ||
height: 1.5rem; | ||
width: 1.5rem; | ||
display: flex; | ||
align-items: center; | ||
justify-self: center; | ||
background-color: transparent; | ||
box-shadow: unset; | ||
.MuiGrid-root { | ||
padding: 0; | ||
display: flex; | ||
svg { | ||
font-size: $text-xxl; | ||
color: transparent; | ||
z-index: 1; | ||
position: relative; | ||
&:hover { | ||
color: transparent; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/aimcore/web/ui/src/components/AudioPlayer/AudioPlayer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
|
||
import ErrorBoundary from 'components/ErrorBoundary'; | ||
import { Tooltip, Text } from 'components/kit_v2'; | ||
|
||
import { Button, Icon, Spinner } from '../kit'; | ||
|
||
import { AudioPlayerProps, AudioPlayerProgress, AudioPlayerVolume } from '.'; | ||
|
||
import './AudioPlayer.scss'; | ||
|
||
function AudioPlayer(props: AudioPlayerProps) { | ||
const { | ||
preload = 'metadata', | ||
muted = true, | ||
autoPlay = true, | ||
audioRef, | ||
src, | ||
onEnded, | ||
onCanPlay, | ||
onPlay, | ||
onPause, | ||
isPlaying = false, | ||
processing = false, | ||
caption = '', | ||
readyToPlay = false, | ||
onDownload, | ||
} = props; | ||
|
||
return ( | ||
<ErrorBoundary> | ||
<div className='AudioPlayer'> | ||
<div className='AudioPlayer__controllers'> | ||
<div className='AudioPlayer__controllers__player'> | ||
<audio | ||
ref={audioRef} | ||
src={src} | ||
preload={preload} | ||
muted={muted} | ||
autoPlay={autoPlay} | ||
onEnded={onEnded} | ||
onCanPlay={onCanPlay} | ||
onPlay={onPlay} | ||
onPause={onPause} | ||
/> | ||
<> | ||
{processing ? ( | ||
<Spinner | ||
className='Icon__container' | ||
size={12} | ||
color='#414b6d' | ||
thickness={2} | ||
/> | ||
) : ( | ||
<Button | ||
onClick={isPlaying ? onPause : onPlay} | ||
color='secondary' | ||
withOnlyIcon | ||
size='xSmall' | ||
> | ||
<Icon name={isPlaying ? 'pause' : 'play'} /> | ||
</Button> | ||
)} | ||
</> | ||
</div> | ||
<AudioPlayerProgress | ||
audio={audioRef.current} | ||
isPlaying={isPlaying} | ||
src={src} | ||
disabled={!readyToPlay} | ||
/> | ||
<AudioPlayerVolume audio={audioRef.current} /> | ||
<div className='AudioPlayer__controllers__download'> | ||
<Button withOnlyIcon size='xSmall' onClick={onDownload}> | ||
{processing ? ( | ||
<Spinner | ||
className='Icon__container' | ||
size={12} | ||
color='#414b6d' | ||
thickness={2} | ||
/> | ||
) : ( | ||
<Icon name='download' /> | ||
)} | ||
</Button> | ||
</div> | ||
</div> | ||
{caption ? ( | ||
<Tooltip content={caption} contentProps={{ side: 'bottom' }}> | ||
<Text as='p' weight={400} size={8} ellipsis css={{ marginTop: 4 }}> | ||
{caption} | ||
</Text> | ||
</Tooltip> | ||
) : null} | ||
</div> | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
AudioPlayer.displayName = 'AudioPlayer'; | ||
export default AudioPlayer; |
6 changes: 6 additions & 0 deletions
6
src/aimcore/web/ui/src/components/AudioPlayer/AudioPlayerProgress/AudioPlayerProgress.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface AudioPlayerProgressProps { | ||
audio: HTMLAudioElement | null; | ||
isPlaying: boolean; | ||
src: string; | ||
disabled?: boolean; | ||
} |
75 changes: 75 additions & 0 deletions
75
src/aimcore/web/ui/src/components/AudioPlayer/AudioPlayerProgress/AudioPlayerProgress.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@use 'src/styles/abstracts' as *; | ||
|
||
.AudioPlayerProgress { | ||
display: flex; | ||
align-items: center; | ||
width: 100%; | ||
&__timer { | ||
display: flex; | ||
span { | ||
width: 2rem; | ||
text-align: right; | ||
@include monospaceFontFamily(); | ||
&:last-child { | ||
text-align: left; | ||
} | ||
} | ||
&-long { | ||
min-width: toRem(74px); | ||
span { | ||
min-width: 2.5rem; | ||
text-align: right; | ||
display: inline-block; | ||
&:last-child { | ||
text-align: left; | ||
} | ||
} | ||
} | ||
} | ||
&__progressSlider { | ||
margin: 0 $space-xxxs 0 $space-xxs; | ||
height: toRem(40px); | ||
.MuiSlider-root { | ||
height: 100% !important; | ||
} | ||
&.Slider { | ||
&:hover { | ||
.MuiSlider-thumb { | ||
opacity: 1; | ||
visibility: visible; | ||
} | ||
.Mui-disabled { | ||
.MuiSlider-thumb { | ||
opacity: 0; | ||
visibility: hidden; | ||
} | ||
} | ||
} | ||
.MuiSlider { | ||
&-root { | ||
height: 0.375rem; | ||
display: flex; | ||
align-items: center; | ||
} | ||
&-thumb { | ||
width: 0.5rem; | ||
height: 0.5rem; | ||
box-shadow: unset; | ||
margin-top: 0; | ||
transition: opacity 0.18s ease-out; | ||
opacity: 0; | ||
visibility: hidden; | ||
&:hover { | ||
box-shadow: unset; | ||
} | ||
&::after { | ||
width: toRem(18px); | ||
height: toRem(22px); | ||
top: toRem(-6px); | ||
left: toRem(-5px); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/aimcore/web/ui/src/components/AudioPlayer/AudioPlayerVolume/AudioPlayerVolume.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface AudioPlayerVolumeProps { | ||
audio: HTMLAudioElement | null; | ||
} |
Oops, something went wrong.