Music.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <script setup lang="ts">
  2. import { useVideo } from "@/store/Video/index";
  3. const router = useRouter();
  4. const store = useVideo();
  5. const stateAu = ref(false);
  6. store.$subscribe((mutation: any, state: any) => {
  7. var audio = document.getElementById("music1");
  8. if (state.isVideo) {
  9. stateAu.value = false;
  10. audio.pause();
  11. } else {
  12. stateAu.value = true;
  13. audio.play();
  14. }
  15. });
  16. const getAssetURL = (image: string) => {
  17. return new URL(`../assets/icon/${image}`, import.meta.url).href;
  18. };
  19. const onChange = () => {
  20. stateAu.value = !stateAu.value;
  21. var audio = document.getElementById("music1");
  22. if (stateAu.value) {
  23. console.log("play");
  24. audio.play();
  25. } else {
  26. console.log("pause");
  27. audio.pause();
  28. }
  29. };
  30. // onMounted(() => {
  31. // if (audio && audio.paused) {
  32. // audio.play();
  33. // }
  34. // });
  35. </script>
  36. <template>
  37. <div class="music" @click="onChange">
  38. <audio
  39. src="./audio/黄扬苏幕 - 鸠兹春盛.mp3"
  40. controls
  41. loop
  42. id="music1"
  43. hidden
  44. playsinline
  45. ></audio>
  46. <img
  47. :src="stateAu ? getAssetURL('play.png') : getAssetURL('pause.png')"
  48. alt=""
  49. />
  50. </div>
  51. </template>
  52. <style lang="less" scoped>
  53. .music {
  54. z-index: 1000;
  55. position: fixed;
  56. top: 10px;
  57. right: 10px;
  58. .audio-box {
  59. // display:;
  60. }
  61. img {
  62. width: 10vw;
  63. height: 10vw;
  64. }
  65. }
  66. </style>