123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import { defineComponent, Transition, Teleport, onMounted, onUnmounted } from 'vue'
- import runtime, * as RuntimeUtils from '/src/pages/detail/runtime'
- import detailState from '/src/pages/detail/state'
- import { Button } from 'vant'
- import { evaluatingRef, startButtonShow } from './'
- import ButtonIcon from './icon'
- import { useMenu, useWiredHeadsetCheck } from '../uses'
- import styles from './index.module.less'
- export default defineComponent({
- name: 'ButtonsPlayer',
- setup() {
- const [wiredStatus] = useWiredHeadsetCheck()
- const reset = () => {
- if (detailState.activeTick > -1) {
- return
- }
- RuntimeUtils.setCurrentTime(0)
- RuntimeUtils.ended(new Event('ended'))
- }
- // 播放进入的圆周长
- const circleLength = Math.floor(2 * Math.PI * 16)
- const changePlay = (res: any) => {
- if (res?.data?.api === 'setPlayState') {
- console.log('父页面的切换事件', res.data, runtime.playState)
- if (runtime.playState == 'play') {
- RuntimeUtils.setPlayState()
- }
- RuntimeUtils.stopTick()
- reset()
- }
- }
-
- onMounted(() => {
- window.addEventListener('message', changePlay)
- })
- onUnmounted(() => {
- window.removeEventListener('message', changePlay)
- })
- return () => {
- const playProgress = (runtime.currentTimeNum / runtime.durationNum) * circleLength
- return (
- <Teleport to="body">
- <div class={styles.player} id="globalPlayer">
- {!runtime.evaluatingStatus && (
- <>
- {(runtime.playState === 'pause' || runtime.playState === 'suspend') &&
- runtime.currentTimeNum > 0 &&
- !detailState.sectionStatus && (
- <Button class={[styles.button, styles.fullbtn]} onClick={reset}>
- <ButtonIcon key="reset" name="reset" />
- </Button>
- )}
- <Button
- class={[styles.button, styles.fullbtn]}
- style={{
- marginLeft: '14px',
- }}
- disabled={detailState.activeDetail?.isAppPlay && detailState.midiPlayIniting}
- onClick={() => {
- RuntimeUtils.setPlayState()
- }}
- >
- <div class={styles.schedule}>
- <div class={styles.schedule}>
- {runtime.playState === 'play' ? (
- <ButtonIcon key="pause" name="pause" />
- ) : (
- <ButtonIcon key="play" name="play" />
- )}
- {runtime.currentTimeNum > 0 && !detailState.sectionStatus && (
- <svg
- class={styles.ring}
- width="40"
- height="40"
- viewBox="0 0 40 40"
- xmlns="http://www.w3.org/200/svg"
- >
- <circle
- cx="20"
- cy="20"
- r="16"
- fill="none"
- stroke="#fff"
- stroke-width="2"
- stroke-linecap="round"
- />
- <circle
- class={styles.fillring}
- cx="20"
- cy="20"
- r="16"
- fill="none"
- stroke="#FFC459"
- stroke-width="2"
- stroke-linecap="round"
- stroke-dasharray={playProgress + ',10000'}
- />
- </svg>
- )}
- </div>
- </div>
- </Button>
- </>
- )}
- </div>
- </Teleport>
- )
- }
- },
- })
|