player.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { defineComponent, Transition, Teleport, onMounted, onUnmounted } from 'vue'
  2. import runtime, * as RuntimeUtils from '/src/pages/detail/runtime'
  3. import detailState from '/src/pages/detail/state'
  4. import { Button } from 'vant'
  5. import { evaluatingRef, startButtonShow } from './'
  6. import ButtonIcon from './icon'
  7. import { useMenu, useWiredHeadsetCheck } from '../uses'
  8. import styles from './index.module.less'
  9. export default defineComponent({
  10. name: 'ButtonsPlayer',
  11. setup() {
  12. const [wiredStatus] = useWiredHeadsetCheck()
  13. const reset = () => {
  14. if (detailState.activeTick > -1) {
  15. return
  16. }
  17. RuntimeUtils.setCurrentTime(0)
  18. RuntimeUtils.ended(new Event('ended'))
  19. }
  20. // 播放进入的圆周长
  21. const circleLength = Math.floor(2 * Math.PI * 16)
  22. const changePlay = (res: any) => {
  23. if (res?.data?.api === 'setPlayState') {
  24. console.log('父页面的切换事件', res.data, runtime.playState)
  25. if (runtime.playState == 'play') {
  26. RuntimeUtils.setPlayState()
  27. }
  28. RuntimeUtils.stopTick()
  29. reset()
  30. }
  31. }
  32. onMounted(() => {
  33. window.addEventListener('message', changePlay)
  34. })
  35. onUnmounted(() => {
  36. window.removeEventListener('message', changePlay)
  37. })
  38. return () => {
  39. const playProgress = (runtime.currentTimeNum / runtime.durationNum) * circleLength
  40. return (
  41. <Teleport to="body">
  42. <div class={styles.player} id="globalPlayer">
  43. {!runtime.evaluatingStatus && (
  44. <>
  45. {(runtime.playState === 'pause' || runtime.playState === 'suspend') &&
  46. runtime.currentTimeNum > 0 &&
  47. !detailState.sectionStatus && (
  48. <Button class={[styles.button, styles.fullbtn]} onClick={reset}>
  49. <ButtonIcon key="reset" name="reset" />
  50. </Button>
  51. )}
  52. <Button
  53. class={[styles.button, styles.fullbtn]}
  54. style={{
  55. marginLeft: '14px',
  56. }}
  57. disabled={detailState.activeDetail?.isAppPlay && detailState.midiPlayIniting}
  58. onClick={() => {
  59. RuntimeUtils.setPlayState()
  60. }}
  61. >
  62. <div class={styles.schedule}>
  63. <div class={styles.schedule}>
  64. {runtime.playState === 'play' ? (
  65. <ButtonIcon key="pause" name="pause" />
  66. ) : (
  67. <ButtonIcon key="play" name="play" />
  68. )}
  69. {runtime.currentTimeNum > 0 && !detailState.sectionStatus && (
  70. <svg
  71. class={styles.ring}
  72. width="40"
  73. height="40"
  74. viewBox="0 0 40 40"
  75. xmlns="http://www.w3.org/200/svg"
  76. >
  77. <circle
  78. cx="20"
  79. cy="20"
  80. r="16"
  81. fill="none"
  82. stroke="#fff"
  83. stroke-width="2"
  84. stroke-linecap="round"
  85. />
  86. <circle
  87. class={styles.fillring}
  88. cx="20"
  89. cy="20"
  90. r="16"
  91. fill="none"
  92. stroke="#FFC459"
  93. stroke-width="2"
  94. stroke-linecap="round"
  95. stroke-dasharray={playProgress + ',10000'}
  96. />
  97. </svg>
  98. )}
  99. </div>
  100. </div>
  101. </Button>
  102. </>
  103. )}
  104. </div>
  105. </Teleport>
  106. )
  107. }
  108. },
  109. })