Giter VIP home page Giter VIP logo

Comments (6)

wuzhe128520 avatar wuzhe128520 commented on August 20, 2024
<div class="song-list-wrap" ref="songListWrap"> 
    <div class="wrapper" v-if="songList && songList.tracks.length">
     <div class="song-item" v-for="song in songList.tracks" :key="song.id" @click.stop="getSong(song.id)"> 
    <div class="song-name ellipsis">{{ song.name }}</div> 
    <p class="song-singer ellipsis">{{ song.ar[0].name }}</p> 
       </div> 
    </div>
 </div>

from vue-music-webapp.

wuzhe128520 avatar wuzhe128520 commented on August 20, 2024
methods: {
getSong (id) {
let musicPlayer = document.getElementById('audio')
console.log('获取audio对象', musicPlayer)
// 异步获取歌曲的url
getSongUrl(id).then(urlData => {
console.log('获取歌曲url', urlData)
if (urlData.code === 200) {
this.songUrl = urlData.data[0].url
// this.$store.state.musicPlayer

      musicPlayer.src = urlData.data[0].url
      musicPlayer.play()
      console.log('musicPlayer', musicPlayer)
    }
}
}

from vue-music-webapp.

caijinyc avatar caijinyc commented on August 20, 2024

移动端游览器限制,无法自动播放。

from vue-music-webapp.

wuzhe128520 avatar wuzhe128520 commented on August 20, 2024

移动端游览器限制,无法自动播放。

不是自动播放,就是手动调用audio.play()

from vue-music-webapp.

caijinyc avatar caijinyc commented on August 20, 2024

为什么 audio 不用 ref 获取嘞

我的逻辑是 watch url 的变化,如果 url 变化那么 this.$refs.auido = newUrl

因为 audio 标签已经设置的 autoplay 所以就会自动播放歌曲了。如果设置了 autoplay 就不用手动调用 play() 了呀,你是不是没有加?

from vue-music-webapp.

wuzhe128520 avatar wuzhe128520 commented on August 20, 2024

为什么 audio 不用 ref 获取嘞

我的逻辑是 watch url 的变化,如果 url 变化那么 this.$refs.auido = newUrl

因为 audio 标签已经设置的 autoplay 所以就会自动播放歌曲了。如果设置了 autoplay 就不用手动调用 play() 了呀,你是不是没有加?

嗯,我没有设置autoplay,是点击歌曲的时候,调用的play(),audio是通过ref获取的,存在vuex里了

from vue-music-webapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.