Co-authored-by: luowei <glpat-EjySCyNjWiLqAED-YmwM> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>tags/0.5.9
| const audioUrl = URL.createObjectURL(blob) | const audioUrl = URL.createObjectURL(blob) | ||||
| const audio = new Audio(audioUrl) | const audio = new Audio(audioUrl) | ||||
| audioRef.current = audio | audioRef.current = audio | ||||
| audio.play().then(() => { | |||||
| setIsPlaying(true) | |||||
| }).catch(() => { | |||||
| audio.play().then(() => {}).catch(() => { | |||||
| setIsPlaying(false) | setIsPlaying(false) | ||||
| URL.revokeObjectURL(audioUrl) | URL.revokeObjectURL(audioUrl) | ||||
| }) | }) | ||||
| audio.onended = () => setHasEnded(true) | |||||
| audio.onended = () => { | |||||
| setHasEnded(true) | |||||
| setIsPlaying(false) | |||||
| } | |||||
| } | } | ||||
| catch (error) { | catch (error) { | ||||
| setIsPlaying(false) | setIsPlaying(false) | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| const togglePlayPause = () => { | const togglePlayPause = () => { | ||||
| if (audioRef.current) { | if (audioRef.current) { | ||||
| if (isPlaying) { | if (isPlaying) { | ||||
| setPause(true) | |||||
| audioRef.current.pause() | |||||
| } | |||||
| else if (!hasEnded) { | |||||
| setPause(false) | |||||
| audioRef.current.play() | |||||
| if (!hasEnded) { | |||||
| setPause(false) | |||||
| audioRef.current.play() | |||||
| } | |||||
| if (!isPause) { | |||||
| setPause(true) | |||||
| audioRef.current.pause() | |||||
| } | |||||
| } | } | ||||
| else if (!isPlaying) { | else if (!isPlaying) { | ||||
| playAudio().then() | |||||
| if (isPause) { | |||||
| setPause(false) | |||||
| audioRef.current.play() | |||||
| } | |||||
| else { | |||||
| setHasEnded(false) | |||||
| playAudio().then() | |||||
| } | |||||
| } | } | ||||
| setIsPlaying(prevIsPlaying => !prevIsPlaying) | setIsPlaying(prevIsPlaying => !prevIsPlaying) | ||||
| } | } | ||||
| else { | else { | ||||
| playAudio().then() | |||||
| setIsPlaying(true) | |||||
| if (!isPlaying) | |||||
| playAudio().then() | |||||
| } | } | ||||
| } | } | ||||
| className={`box-border p-0.5 flex items-center justify-center cursor-pointer ${isAudition || 'rounded-md bg-white'}`} | className={`box-border p-0.5 flex items-center justify-center cursor-pointer ${isAudition || 'rounded-md bg-white'}`} | ||||
| style={{ boxShadow: !isAudition ? '0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)' : '' }} | style={{ boxShadow: !isAudition ? '0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)' : '' }} | ||||
| onClick={togglePlayPause}> | onClick={togglePlayPause}> | ||||
| <div className={`w-6 h-6 rounded-md ${!isAudition ? 'hover:bg-gray-200' : 'hover:bg-gray-50'} ${!isPause ? ((isPlaying && !hasEnded) ? s.playIcon : s.stopIcon) : s.pauseIcon}`}></div> | |||||
| <div className={`w-6 h-6 rounded-md ${!isAudition ? 'hover:bg-gray-200' : 'hover:bg-gray-50'} ${(isPlaying && !hasEnded) ? s.pauseIcon : s.playIcon}`}></div> | |||||
| </div> | </div> | ||||
| </Tooltip> | </Tooltip> | ||||
| </div> | </div> |
| background-position: center; | background-position: center; | ||||
| background-repeat: no-repeat; | background-repeat: no-repeat; | ||||
| } | } | ||||
| .stopIcon { | |||||
| background-position: center; | |||||
| background-repeat: no-repeat; | |||||
| background-image: url(~@/app/components/develop/secret-key/assets/stop.svg); | |||||
| } |
| <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> | <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||||
| <g clip-path="url(#clip0_129_107)"> | <g clip-path="url(#clip0_129_107)"> | ||||
| <path d="M7.99991 14.6666C11.6819 14.6666 14.6666 11.6819 14.6666 7.99998C14.6666 4.31808 11.6819 1.33331 7.99998 1.33331C4.31808 1.33331 1.33331 4.31808 1.33331 7.99998C1.33331 11.6819 4.31808 14.6666 7.99998 14.6666Z" stroke="#155EEF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> | |||||
| <path d="M6.66665 5.33331L10.6666 7.99998L6.66665 10.6666V5.33331Z" stroke="#155EEF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> | |||||
| <path d="M7.99998 14.6666C11.6819 14.6666 14.6666 11.6819 14.6666 7.99998C14.6666 4.31808 11.6819 1.33331 7.99998 1.33331C4.31808 1.33331 1.33331 4.31808 1.33331 7.99998C1.33331 11.6819 4.31808 14.6666 7.99998 14.6666Z" stroke="#667085" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> | |||||
| <path d="M6.66665 5.33331L10.6666 7.99998L6.66665 10.6666V5.33331Z" stroke="#667085" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> | |||||
| </g> | </g> | ||||
| <defs> | <defs> | ||||
| <clipPath id="clip0_129_107"> | <clipPath id="clip0_129_107"> |
| <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> | |||||
| <g clip-path="url(#clip0_129_107)"> | |||||
| <path d="M7.99998 14.6666C11.6819 14.6666 14.6666 11.6819 14.6666 7.99998C14.6666 4.31808 11.6819 1.33331 7.99998 1.33331C4.31808 1.33331 1.33331 4.31808 1.33331 7.99998C1.33331 11.6819 4.31808 14.6666 7.99998 14.6666Z" stroke="#667085" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> | |||||
| <path d="M6.66665 5.33331L10.6666 7.99998L6.66665 10.6666V5.33331Z" stroke="#667085" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> | |||||
| </g> | |||||
| <defs> | |||||
| <clipPath id="clip0_129_107"> | |||||
| <rect width="16" height="16" fill="white"/> | |||||
| </clipPath> | |||||
| </defs> | |||||
| </svg> |