Comments (7)
Hi, @Simoneth, check your dynamic import, according to the NextJS docs first argument has to be a function
from wavesurfer-react.
@Simoneth, I've created next-project
{
...,
"next": "13.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"wavesurfer-react": "2.2.2",
"wavesurfer.js": "6.4.0",
...
}
Within the project, I implemented the following component:
import { useCallback, useMemo, useRef, useState } from 'react';
import { WaveSurfer, WaveForm, Region, Marker } from 'wavesurfer-react';
import RegionsPlugin from 'wavesurfer.js/dist/plugin/wavesurfer.regions.min';
import TimelinePlugin from 'wavesurfer.js/dist/plugin/wavesurfer.timeline.min';
import MarkersPlugin from 'wavesurfer.js/src/plugin/markers';
export default function Wavesurfer({ id }) {
const waveformId = 'waveform' + '-' + id;
const timelineId = `timeline-${id}`;
const plugins = useMemo(() => {
return [
{
plugin: RegionsPlugin,
options: { dragSelection: true },
},
{
plugin: TimelinePlugin,
options: {
container: timelineId,
},
},
{
plugin: MarkersPlugin,
options: {
markers: [{ draggable: true }],
},
},
];
}, [timelineId]);
const [regions, setRegions] = useState([
{
id: 'region-1',
start: 0.5,
end: 10,
color: 'rgba(0, 0, 0, .5)',
data: {
systemRegionId: 31,
},
},
{
id: 'region-2',
start: 5,
end: 25,
color: 'rgba(225, 195, 100, .5)',
data: {
systemRegionId: 32,
},
},
{
id: 'region-3',
start: 15,
end: 35,
color: 'rgba(25, 95, 195, .5)',
data: {
systemRegionId: 33,
},
},
]);
const [markers, setMarkers] = useState([
{
time: 5.5,
label: 'V1',
color: '#ff990a',
draggable: true,
},
{
time: 10,
label: 'V2',
color: '#00ffcc',
position: 'top',
},
]);
const wavesurferRef = useRef(null);
const onWaveSurferMount = useCallback((waveSurfer) => {
if (waveSurfer.markers) {
waveSurfer.clearMarkers();
}
wavesurferRef.current = waveSurfer;
if (wavesurferRef.current) {
wavesurferRef.current.load('/audios/1.mp3');
wavesurferRef.current.on('ready', () => {
console.log('WaveSurfer is ready');
});
wavesurferRef.current.on('region-removed', (region) => {
console.log('region-removed --> ', region);
});
wavesurferRef.current.on('loading', (data) => {
console.log('loading --> ', data);
});
}
}, []);
return (
<WaveSurfer plugins={plugins} onMount={onWaveSurferMount}>
<WaveForm id={waveformId}>
{regions.map((regionProps) => (
<Region
onUpdateEnd={() => {}}
key={regionProps.id}
{...regionProps}
/>
))}
{markers.map((marker, index) => {
return (
<Marker
key={index}
{...marker}
onClick={(...args) => {
console.log('onClick', ...args);
}}
onDrag={(...args) => {
console.log('onDrag', ...args);
}}
onDrop={(...args) => {
console.log('onDrop', ...args);
}}
/>
);
})}
</WaveForm>
<div id={timelineId}></div>
</WaveSurfer>
);
}
At first run, I received the same error about container being not specified, but I found out that I made a mistake in plugins props. After the following change everything start to work:
...
const plugins = useMemo(() => {
return [
{
plugin: RegionsPlugin,
options: { dragSelection: true },
},
{
plugin: TimelinePlugin,
options: {
// old value was only timelineId
container: '#' + timelineId,
},
},
{
plugin: MarkersPlugin,
options: {
markers: [{ draggable: true }],
},
},
];
}, [timelineId]);
...
Thus, make sure that both id in plugins list and in div, that is considered to be a timeline container contain and receive (respectively) the same value taking into account that container in plugins should also be prefixed with "#". Currently timeline will not rebuild if some of its props would change.
from wavesurfer-react.
@Simoneth, ShiiRochi | Experimental Next Project
from wavesurfer-react.
Here my Wavesurfer component:
import { WaveSurfer, WaveForm, Region } from "wavesurfer-react";
import RegionsPlugin from "wavesurfer.js/dist/plugin/wavesurfer.regions.min";
import TimelinePlugin from "wavesurfer.js/dist/plugin/wavesurfer.timeline.min";
export default function Wavesurfer(props) {
const [timelineVis] = useState(true);
const minSec = 5;
const maxSec = 30;
const absoluteMaxRegions = 20;
const [maxRegions, setMaxRegions] = useState();
const plugins = useMemo(() => {
return [
{
plugin: RegionsPlugin,
options: { dragSelection: true }
},
timelineVis && {
plugin: TimelinePlugin,
options: {
container: "#timeline" + props.id
}
}
].filter(Boolean);
}, [timelineVis]);
return (
<WaveSurfer plugins={plugins} onMount={handleWSMount}>
<WaveForm
id={"waveform" + props.id}
cursorColor="OrangeRed"
progressColor="#00a3ff"
barWidth="3"
barRadius="3"
responsive="true"
partialRender="true"
>
{props.regions.map((regionProps) => (
<Region
onUpdateEnd={handleRegionUpdate}
key={regionProps.id}
minLength={minSec}
maxLength={maxSec}
maxRegions={maxRegions}
{...regionProps}
/>
))}
</WaveForm>
<div className="timeline" id={"timeline" + props.id} />
</WaveSurfer>
)
And how I call it:
import dynamic from 'next/dynamic';
const Wavesurfer = dynamic(import('src/components/wavesurfer'), { ssr: false })
from wavesurfer-react.
Thanks,
So, I changed the import to this:
const Wavesurfer = dynamic(() => import('src/components/wavesurfer'), {
ssr: false,
})
The previous error has disappeared, but it doesn't solve the general problem for me:
from wavesurfer-react.
Sorry again for the inconvenience but could you give me a link to see your example...that would really help, because I still can't figure it out.
Thanks!
from wavesurfer-react.
Thanks,
I finally figured out that mine was a re-rendering issue (my id was auto-generated dynamically via props).
from wavesurfer-react.
Related Issues (20)
- Waveform customisation HOT 2
- Can not get zoom to work HOT 5
- recreate timeline if its id is changed HOT 1
- "Cannot use import statement outside a module" with Next.js HOT 3
- getCurrentTime without triggering too much re-render on the Component HOT 2
- Is it possible to use this with Tauri / NextJS SSG? HOT 2
- generating new markers in component wrapped by <StrictMode> not rendering new markers HOT 4
- wavesurfer-react with react-beautiful-dnd issue HOT 5
- Align the button- Should be at the bottom of each waveform HOT 1
- Support content for regions HOT 3
- Support for wavesurfer.js 7+ HOT 5
- wavesurfer-react: V3 HOT 18
- audio load issue HOT 2
- codesandbox code issue HOT 2
- add first-interaction github action
- improve demo webpage
- Minimap support HOT 1
- Issue with changing the style of the waveform scrollbar HOT 1
- How to get the list of all regions? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wavesurfer-react.