|
@@ -1,8 +1,7 @@
|
|
|
import { defineComponent, onMounted, reactive, ref } from 'vue';
|
|
|
-import WaveSurfer from 'wavesurfer.js';
|
|
|
+// import WaveSurfer from 'wavesurfer.js';
|
|
|
+// import Regions from 'wavesurfer.js/dist/plugins/regions.js';
|
|
|
import styles from './index.module.less';
|
|
|
-import MSticky from '@/components/m-sticky';
|
|
|
-import MHeader from '@/components/m-header';
|
|
|
import { Cell, Image, List, Popup, Slider } from 'vant';
|
|
|
import iconMember from './images/icon-member.png';
|
|
|
import iconZan from './images/icon-zan.png';
|
|
@@ -42,6 +41,7 @@ export default defineComponent({
|
|
|
musicDetail: {} as any,
|
|
|
timer: null as any,
|
|
|
paused: true,
|
|
|
+ audioWidth: 0,
|
|
|
currentTime: 0,
|
|
|
duration: 0.1,
|
|
|
loop: false,
|
|
@@ -59,6 +59,7 @@ export default defineComponent({
|
|
|
}
|
|
|
});
|
|
|
const wavesurfer = ref();
|
|
|
+ // window.AudioContext = window.AudioContext || window.webkitAudioContext;
|
|
|
const audioDom = new Audio();
|
|
|
audioDom.controls = true;
|
|
|
audioDom.style.width = '100%';
|
|
@@ -150,45 +151,61 @@ export default defineComponent({
|
|
|
};
|
|
|
|
|
|
const initAudio = () => {
|
|
|
- wavesurfer.value = WaveSurfer.create({
|
|
|
- container: document.querySelector(`#${audioId}`) as HTMLElement,
|
|
|
- waveColor: '#fff',
|
|
|
- progressColor: '#2FA1FD',
|
|
|
- url: state.musicDetail.videoUrl,
|
|
|
- cursorWidth: 0,
|
|
|
- height: 35,
|
|
|
- width: 'auto',
|
|
|
- normalize: true,
|
|
|
- // Set a bar width
|
|
|
- barWidth: 2,
|
|
|
- // Optionally, specify the spacing between bars
|
|
|
- barGap: 2,
|
|
|
- // And the bar radius
|
|
|
- barRadius: 4,
|
|
|
- barHeight: 0.6,
|
|
|
- autoScroll: true,
|
|
|
- /** If autoScroll is enabled, keep the cursor in the center of the waveform during playback */
|
|
|
- autoCenter: true,
|
|
|
- hideScrollbar: false,
|
|
|
- media: audioDom
|
|
|
- });
|
|
|
+ try {
|
|
|
+ audioDom.src = state.musicDetail.videoUrl;
|
|
|
+ audioDom.load();
|
|
|
+ audioDom.oncanplaythrough = () => {
|
|
|
+ state.paused = audioDom.paused;
|
|
|
+ state.duration = audioDom.duration;
|
|
|
+ };
|
|
|
+ // 播放时监听
|
|
|
+ audioDom.addEventListener('timeupdate', () => {
|
|
|
+ state.currentTime = audioDom.currentTime;
|
|
|
+ const rate = (state.currentTime / state.duration) * 100;
|
|
|
+ state.audioWidth = rate > 100 ? 100 : rate;
|
|
|
+ });
|
|
|
+ audioDom.addEventListener('ended', () => {
|
|
|
+ state.paused = audioDom.paused;
|
|
|
+ });
|
|
|
+ // wavesurfer.value = WaveSurfer.create({
|
|
|
+ // container: document.querySelector(`#${audioId}`) as HTMLElement,
|
|
|
+ // waveColor: '#fff',
|
|
|
+ // progressColor: '#2FA1FD',
|
|
|
+ // url: state.musicDetail.videoUrl,
|
|
|
+ // cursorWidth: 0,
|
|
|
+ // height: 35,
|
|
|
+ // width: 'auto',
|
|
|
+ // normalize: true,
|
|
|
+ // // Set a bar width
|
|
|
+ // barWidth: 2,
|
|
|
+ // // Optionally, specify the spacing between bars
|
|
|
+ // barGap: 2,
|
|
|
+ // // And the bar radius
|
|
|
+ // barRadius: 4,
|
|
|
+ // barHeight: 1.2,
|
|
|
+ // /** If autoScroll is enabled, keep the cursor in the center of the waveform during playback */
|
|
|
+ // // autoCenter: true,
|
|
|
+ // hideScrollbar: false,
|
|
|
+ // media: audioDom
|
|
|
+ // });
|
|
|
+ // // console.log(wavesurfer.value);
|
|
|
|
|
|
- wavesurfer.value.once('interaction', () => {
|
|
|
- // wavesurfer.value.play();
|
|
|
- });
|
|
|
- wavesurfer.value.once('ready', () => {
|
|
|
- state.paused = audioDom.paused;
|
|
|
- state.duration = audioDom.duration;
|
|
|
- });
|
|
|
+ // // const wsRegions = wavesurfer.value.registerPlugin(Regions.create());
|
|
|
+ // wavesurfer.value.once('interaction', () => {
|
|
|
+ // // wavesurfer.value.play();
|
|
|
+ // });
|
|
|
+ // wavesurfer.value.once('ready', () => {
|
|
|
+ // state.paused = audioDom.paused;
|
|
|
+ // state.duration = audioDom.duration;
|
|
|
+ // });
|
|
|
|
|
|
- wavesurfer.value.on('finish', () => {
|
|
|
- state.paused = true;
|
|
|
- });
|
|
|
-
|
|
|
- // 播放时监听
|
|
|
- audioDom.addEventListener('timeupdate', () => {
|
|
|
- state.currentTime = audioDom.currentTime;
|
|
|
- });
|
|
|
+ // wavesurfer.value.on('finish', () => {
|
|
|
+ // state.paused = true;
|
|
|
+ // });
|
|
|
+ } catch (e) {
|
|
|
+ //
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const __init = async () => {
|
|
@@ -250,11 +267,17 @@ export default defineComponent({
|
|
|
{state.playType === 'Audio' && (
|
|
|
<div class={styles.audioSection}>
|
|
|
<div class={styles.audioContainer}>
|
|
|
- <div
|
|
|
+ {/* <div
|
|
|
id={audioId}
|
|
|
onClick={(e: MouseEvent) => {
|
|
|
e.stopPropagation();
|
|
|
+ }}></div> */}
|
|
|
+ <div
|
|
|
+ class={styles.waveActive}
|
|
|
+ style={{
|
|
|
+ width: state.audioWidth + '%'
|
|
|
}}></div>
|
|
|
+ <div class={styles.waveDefault}></div>
|
|
|
</div>
|
|
|
|
|
|
<div class={styles.audioBox}>
|
|
@@ -396,7 +419,7 @@ export default defineComponent({
|
|
|
<LoginModel
|
|
|
onClose={() => (state.loginStatus = false)}
|
|
|
onConfirm={async (val: boolean) => {
|
|
|
- state.loginStatus = val;
|
|
|
+ state.loginTag = val;
|
|
|
state.loginStatus = false;
|
|
|
const { data } = await api_openUserMusicDetail(state.id);
|
|
|
state.musicDetail = data;
|