punxaphil / maxi-media-player

Media card for Home Assistant UI with a focus on managing multiple media players, but not excluding single player setups.
7 stars 1 forks source link

fix: volume and mute not changing for single player setup #16

Closed thlucas1 closed 2 months ago

thlucas1 commented 2 months ago

Phil - here is the other fix I had in my original PR request that contained multiple items. It fixes the issue with the volume slider and mute buttons not working when using a single player.

I also added the ".vs\" to gitignore for Visual Studio Community Edition use.

punxaphil commented 2 months ago

Thanks! I'll take a look

punxaphil commented 2 months ago

I really appreciate you letting me know about this bug. Your solution probably works great, but the main problem is that members is empty. Which it by design shouldn't be. I avoided this with a smaller fix as you can see here: fix: volume and mute not changing for single player setup

punxaphil commented 2 months ago

fix released here: https://github.com/punxaphil/maxi-media-player/releases/tag/v1.5.1

thlucas1 commented 2 months ago

I updated to v1.5.1 via HACS and restarted, but fix did not work - still no mute and no volume. I verified that I removed the test script that I was using, and it's using the /hacsfiles/maxi-media-player/maxi-media-player.js?hacstag=770072954150 resource.

What is odd is that the volume slider will move and stay to where I adjust it to, but a volume_set request is not passed on to the media_player. I have detailed tracing enabled in my media player, and it is not receiving a volume set request. The mute button does not toggle nor receive a mute request either.

Are you sure the members array is empty when the volumeSet method is called?

I still think you need the if ((updateMembers) && (player.members.length > 0)) { logic in the media-control-service.ts \ volumeSet method - you only want to execute volumeSetGroup if you are updating multiple players AND there is at least 1 member in the group; or change the way you are calling the volumeSet method to use updateMembers = false.

  async volumeSet(player: MediaPlayer, volume: number, updateMembers: boolean) {
    if ((updateMembers) && (player.members.length > 0)) {
      return await this.volumeSetGroup(player, volume);
    } else {
      return await this.volumeSetSinglePlayer(player, volume);
    }
  }

Here's the YAML I am using for the player:

type: custom:maxi-media-player
sections:
  - player
artworkAsBackground: true
showAudioInputFormat: true
playerVolumeOnlyAffectsMainPlayer: true
entities:
  - media_player.bose_st10_1
  - media_player.bose_st10_2
topFavorites:
  - ''
hideVolumeCogwheel: true
dontSwitchPlayerWhenGrouping: true

Here's a screenshot of what I see: image

Hope it helps!

thlucas1 commented 2 months ago

I did some more testing ... I merged your changes into my main and test branch, and added some console.log() statements to the media-control-service.ts module.

  async volumeSet(player: MediaPlayer, volume: number, updateMembers: boolean) {
    console.log("Maxi Player: volumeSet, player=" + player.name + ", volume=" + JSON.stringify(volume) + ", updateMembers=" + JSON.stringify(updateMembers))
    console.log("Maxi Player: volumeSet, player=" + player.name + ", members=" + JSON.stringify(player.members) + ", members.length=" + JSON.stringify(player.members.length))
...

  async setVolumeMute(mediaPlayer: MediaPlayer, muteVolume: boolean, updateMembers = true) {
    console.log("Maxi Player: setVolumeMute, player=" + mediaPlayer.name + ", muteVolume=" + JSON.stringify(muteVolume) + ", updateMembers=" + JSON.stringify(updateMembers))
    console.log("Maxi Player: setVolumeMute, player=" + mediaPlayer.name + ", members=" + JSON.stringify(mediaPlayer.members) + ", members.length=" + JSON.stringify(mediaPlayer.members.length))
...

Here's what I see in the console log when I execute a mute command:

# output when muting:
Maxi Player: setVolumeMute, player=Bose-ST10-1, muteVolume=true, updateMembers=true
Maxi Player: setVolumeMute, player=Bose-ST10-1, members=[], members.length=0

# output when unmuting:
Maxi Player: setVolumeMute, player=Bose-ST10-1, muteVolume=false, updateMembers=true
Maxi Player: setVolumeMute, player=Bose-ST10-1, members=[], members.length=0

Here's what I see in the console log when I execute a volume change command (using slider move):

# output when raising volume:
Maxi Player: volumeSet, player=Bose-ST10-1, volume=37, updateMembers=true
Maxi Player: volumeSet, player=Bose-ST10-1, members=[], members.length=0

# output when lowering volume:
Maxi Player: volumeSet, player=Bose-ST10-1, volume=15, updateMembers=true
Maxi Player: volumeSet, player=Bose-ST10-1, members=[], members.length=0

I also verified that the .js resource file had your current changes to the createGroupMembers method (compiled to the following):

createGroupMembers(e,t){const A=[];for(const i of st(e))for(const e of t)e.entity_id===i&&A.push(new wt(e,this.config));return null!=A?A:[this]}