import React, { useRef, useEffect } from "react"; import classnames from "classnames"; import { usePicobel } from "./provider"; import { TrackProvider } from "./trackContext"; import { getFileName } from "../../utils/helpers"; import * as Components from "../components/"; export interface PicobelProps { src: string; id?: string; className?: string; theme?: string; children?: React.ReactNode; title?: string; artist?: string; } export const Picobel: React.FC = ({ src, id: providedId, title: providedTitle, theme, artist, className = "", children }) => { const id = providedId || src; const title = providedTitle || getFileName(src); const metadata = { title, artist }; // Audio element reference const audioRef = useRef(null); // Get Picobel context const context = usePicobel(); if (!context) { throw new Error("Picobel must be used within a PicobelProvider"); } const namespace = theme || context.namespace; // Register with context when component mounts useEffect(() => { context.registerTrack({ id, audioRef, src, metadata, namespace }); return () => { context.unregisterTrack(id); }; }, []); // Get current player state const isPlaying = context.isTrackPlaying(id); return (
); }; export default Picobel;