When casting an audiobook from the web there are several bugs when it comes to the playback rate of the book.
1) If you were listening to a book a X speed (1.2x for example) and then press the Cast button to switch players, once you start the book back on the remote device it will always play at 1x speed.
2) The only way to play over Cast at the speed you want is to play the book, change the speed to what you want. Close the player connect to a Cast capable device, and then start the book again. It will play at the speed you've set.
3) The audiobook will always be at the same speed that it was started at and won't be updated.
What did you expect to happen?
The audiobook should be playing at the playback rate that I have set no matter how I start the casting session. While casting I should be able to update the playbackrate and it reflect correctly on the remote device.
Steps to reproduce the issue
1 Start book and set speed to 2x
2 Hit Cast Button and select device
3 Start book
...Book will play at 1x speed
1 Start casting at any speed
2 Change speed
...book will play at speed it was already playing
Audiobookshelf version
V2.11.0
How are you running audiobookshelf?
Docker
What OS is your Audiobookshelf server hosted from?
Linux
If the issue is being seen in the UI, what browsers are you seeing the problem on?
Chrome
Logs
No response
Additional Notes
I downloaded everything to make the fix myself, but couldn't cast working locally from the dev setup. From what I saw while looking through the code and getting it running I believe the answer is in a couple places.
1) CastPlayer.js -> setPlaybackRate method
My quick research shows that in order to change the playback rate of a casted object you have to reload it. I believe that updating this method to set the defaultPlaybackRate if it's changed and then if playWhenReady or the play is already playing then making a BuildCastLoadRequest where the and then follow it with a castLoadMedia call. That should update the session with the new playBackRate. and basically matches what's happening in LocalAudioPlayer.js, but just a little more complicated because it's playing remote.
I believe the above may fix everything, but will be slower and more chattery. Below would clean it up a bit and make less castLoadMedia calls so it would be better with an extra update.
2) PlayerHandler.js
switchPlayer method
Line 86, 105, and 107 are where the players are created. Right after they are created the this.SetPlayerRate(this.initialPlaybackRate) should be called for all 3.
The only call to SetPlayerRate is in playerStateChange if the player gets turned on, but by that time the player is already playing and wont' have the correct playRate...this works with LocalAudioPlayer and LocalVideoPlayer because they are working correctly, and one the above is working it will work too. If it's moved away from every time the player is started to only when the player is first created or when the user actively changes it and setPlayerRate is called then castLoadMedia won't be called every time something is started or stopped.
I'm probably missing something, but that's what I saw with my initial lookthrough and it's all dependent on when the playBackRate is changed on the web app that the new value will be passed to playerHandler.setPlayBackRate.
What happened?
When casting an audiobook from the web there are several bugs when it comes to the playback rate of the book.
1) If you were listening to a book a X speed (1.2x for example) and then press the Cast button to switch players, once you start the book back on the remote device it will always play at 1x speed. 2) The only way to play over Cast at the speed you want is to play the book, change the speed to what you want. Close the player connect to a Cast capable device, and then start the book again. It will play at the speed you've set. 3) The audiobook will always be at the same speed that it was started at and won't be updated.
What did you expect to happen?
The audiobook should be playing at the playback rate that I have set no matter how I start the casting session. While casting I should be able to update the playbackrate and it reflect correctly on the remote device.
Steps to reproduce the issue
1 Start book and set speed to 2x 2 Hit Cast Button and select device 3 Start book ...Book will play at 1x speed
1 Start casting at any speed 2 Change speed ...book will play at speed it was already playing
Audiobookshelf version
V2.11.0
How are you running audiobookshelf?
Docker
What OS is your Audiobookshelf server hosted from?
Linux
If the issue is being seen in the UI, what browsers are you seeing the problem on?
Chrome
Logs
No response
Additional Notes
I downloaded everything to make the fix myself, but couldn't cast working locally from the dev setup. From what I saw while looking through the code and getting it running I believe the answer is in a couple places.
1) CastPlayer.js -> setPlaybackRate method
My quick research shows that in order to change the playback rate of a casted object you have to reload it. I believe that updating this method to set the defaultPlaybackRate if it's changed and then if playWhenReady or the play is already playing then making a BuildCastLoadRequest where the and then follow it with a castLoadMedia call. That should update the session with the new playBackRate. and basically matches what's happening in LocalAudioPlayer.js, but just a little more complicated because it's playing remote.
I believe the above may fix everything, but will be slower and more chattery. Below would clean it up a bit and make less castLoadMedia calls so it would be better with an extra update.
2) PlayerHandler.js
I'm probably missing something, but that's what I saw with my initial lookthrough and it's all dependent on when the playBackRate is changed on the web app that the new value will be passed to playerHandler.setPlayBackRate.