npm i vue-sound
App.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<template> <div class="audio-player-container"> <h2>Vue Sound Audio Player</h2> <!-- File Input for selecting a local audio file --> <input type="file" accept="audio/*" @change="onAudioFileChange" class="file-input" /> <!-- Audio Player --> <vue-sound v-if="audioFile" :file="audioFile" :image="img" title="Selected Audio" details="Local File Playback" show-download /> </div> </template> <script> import { VueSound } from "vue-sound"; import "vue-sound/style.css"; import img from './assets/1.jpeg' export default { name: "AudioPlayerApp", components: { VueSound, }, data() { return { audioFile: null, // Holds the selected audio file URL img }; }, methods: { onAudioFileChange(event) { const file = event.target.files[0]; if (file) { this.audioFile = URL.createObjectURL(file); // Create a URL for the selected audio file } }, }, }; </script> <style scoped> .audio-player-container { padding: 20px; max-width: 600px; margin: 0 auto; text-align: center; font-family: Arial, sans-serif; } .file-input { margin: 10px 0; padding: 10px; font-size: 1rem; } h2 { color: #333; font-size: 1.5rem; margin-bottom: 20px; } </style> |