SevenOutman / vue-aplayer

:cake: Easy-to-use music player for Vue 2.x
https://vue-aplayer.js.org
MIT License
1.32k stars 200 forks source link

Error when changing single music object #10

Closed cassioscabral closed 6 years ago

cassioscabral commented 6 years ago

I got an error within the watch when changing a single music(as an object).

For what I could find this is that APlayer try to access the music as an Array when you use .setMusic(0) (here: https://github.com/SevenOutman/vue-aplayer/blob/master/src/vue-aplayer.vue#L67) You can check more about APlayer in here: https://github.com/MoePlayer/APlayer/blob/master/src/APlayer.js#L449

I tried several ways to change my music without success.

The only solution I found was to create a new player(new APlayer({...options, music: newMusic}) whenever the music change(inside the watch).

Why I did that ? APlayer won't detect a change in the music, it instantiate a new player with every possible music and it has a couple of functions to deal with changes like .addMusic(newMusics) but it has nothing to replace the current music playing. That's why I'm creating a new instance and replacing it. It worked nicely.

I tried to pass the music inside an array [newMusic] which won't raise an error and will trigger the changes of the pic and everything but not the music.

I don't know if anyone had this issue. But I'm forking and will be using mine meanwhile, I will open a PR if you find this helpful . For now, the player is not reactive and I think that should be a most for the Vue version.

Feel free to close this if you wish, is more a reporting and discussion kind of issue. Could be helpful for people with the same issue.

bitbytebit1 commented 6 years ago

Experiencing EXACTLY the same thing here!

SevenOutman commented 6 years ago

@cassioscabral Thanks for your effort. The v1.0.0 version package now supports change in music.

cassioscabral commented 6 years ago

@SevenOutman that's great, thank you