After upgrading from version 7.7.5 to 7.8.5, the wave graph is not rendered #3865
Replies: 5 comments 4 replies
-
7.8.0 introduced lazy rendering. Only the currently visible portion of the waveform is rendered. This change didn’t introduce any public API changes. Make sure your code doesn’t rely on any internal elements. |
Beta Was this translation helpful? Give feedback.
-
I made some changes in your project case and found that the waveform was not rendered. This is similar to what I implemented above. Do you know where the problem is? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi @katspaugh, I have found the problem. The update of version 7.7.15 seems to affect the setMediaElement method. I don't know if it is a bug, but I have solved it by passing the value through the media field when creating. You can verify whether setMediaElement is available when you have time. At present, I found that waveform rendering cannot be performed using this method. |
Beta Was this translation helpful? Give feedback.
-
Hi team, after upgrading from version 7.7.5 to 7.8.5, the wave graph is not rendered. I don't know where the problem is, could you give me some guidance?
Code details:
import React, { CSSProperties, useEffect, useRef, useState } from 'react';
import Box from '@cobalt/react-box';
import { useTheme } from '@cobalt/react-theme-provider';
import AudioPart from 'src/MediaPlayer/audio/AudioPart';
import styles from 'src/UnifiedPlayer/styles/helpers.module.scss';
import { waveReady } from 'src/UnifiedPlayer/utils/wave-utils';
import WaveSurfer from 'wavesurfer.js';
const WaveElementId = 'waveElementId';
const WAVE_HEIGHT = 50;
const BAR_WIDTH = 4;
const BAR_HEIGHT = 0.7;
const BAR_GAP = 2;
type Props = {
onSeek: (absoluteSeekPosition: number) => void;
data: {
audioParts: AudioPart[];
};
hasCookieAuthentication?: boolean;
};
const Waves: React.FC = ({
onSeek,
data,
hasCookieAuthentication = false,
}) => {
const audiosLoaded = useRef(false);
const [audioParts, setAudioParts] = useState<AudioPart[]>([]);
const [waves, setWaves] = useState<WaveSurfer[]>([]);
const [failedIndexes, setFailedIndexes] = useState<number[]>([]);
const theme = useTheme();
const MIDNIGHT_400 = theme.midnight400;
const MIDNIGHT_700 = theme.midnight700;
if (data.audioParts !== audioParts) {
setAudioParts(data.audioParts);
}
const onDestroy = () => {
if (waves?.length) {
// destroy WaveSurfer instances
waves.forEach((wave) => {
wave.unAll();
wave.destroy();
});
};
useEffect(() => {
onDestroy();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [audioParts]);
useEffect(() => {
// wait for wave widths
if (!audioParts.length) {
return;
}
}, [audioParts]);
// Watch for waves array change so we must subscribe to seek events
useEffect(() => {
if (!waves.length || !audiosLoaded.current) {
return;
}
}, [waves, onSeek, audioParts, failedIndexes]);
const wavesContainerStyle = {
backgroundColor: theme.midnight200,
height: WAVE_HEIGHT * 2,
} as CSSProperties;
const audioTotaltime = audioParts.reduce(
(prev, curr) => (curr.audio?.duration || curr.duration) + prev,
0
);
return (
{audioParts.map((audioPart, index) => {
const { audio }: { audio: HTMLAudioElement } = audioPart;
);
};
export default Waves;
Before:
After:
Beta Was this translation helpful? Give feedback.
All reactions