File size: 1,228 Bytes
0b5c6fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use client'

import { Play, Pause, RotateCcw } from 'lucide-react'
import { Button } from "@/components/ui/button"
import React from "react";
import {match} from "ts-pattern"

interface AudioPlaybackProps {
  path: string
}

export default function AudioPlayback({ path }: AudioPlaybackProps) {
  const audioRef = React.useRef<HTMLAudioElement| null>(null);
  
  return (
      <div className="flex items-center space-x-4">
          <Button
              onClick={async () => await audioRef.current?.play()}
              variant="default"
              size="icon"
              className="w-12 h-12 rounded-full bg-gradient-to-r from-green-400 to-blue-500 hover:from-green-500 hover:to-blue-600 transition-all duration-300"
          >
              {match(audioRef.current?.paused).with(true, () => <Pause/>).otherwise(() => <Play/>)}
          </Button>
          <audio controls src={path} autoPlay={!!path} ref={audioRef} className="hidden"></audio>
          <Button
              variant="outline"
              size="icon"
              className="w-12 h-12 rounded-full transition-all duration-300 hover:bg-gray-200"
          >
              <RotateCcw className="w-6 h-6"/>
          </Button>
      </div>
  )
}