移动端chrome78.0版本会出现replaceAll is not a function。解决兼容性问题,请使用 String.replace()进行代替,并使用正则表达式的全局模式进行替换。
//把数组时间转换成秒
let lyricFormated = [];
for (let i = 0; i < lyricUnformatedArray.length; i++) {
let element = lyricUnformatedArray[i].time;
element = element.replace(/\[/g,"").replace(/]/g,"");
// element = element.replaceAll("[", "").replaceAll("]", ""); //兼容性问题
element = element.split(".");
let nanoSecond = element[1];
let minutesAndSeconds = element[0];
minutesAndSeconds = minutesAndSeconds.split(":");
let minutes = minutesAndSeconds[0];
let seconds = minutesAndSeconds[1];
let musicSecond =
parseInt(minutes * 60) +
parseInt(seconds) +
parseFloat(nanoSecond / 1000);
lyricSentence = lyricUnformatedArray[i].lyric;
lyricFormated.push({ time: musicSecond, lyric: lyricSentence });
}