mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-05 02:38:09 -05:00
[web] Fix volume for stream not working in Safari
This commit is contained in:
parent
85e9b06bca
commit
39847bab35
@ -1,23 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Audio handler object
|
* Audio handler object
|
||||||
* Taken from https://github.com/rainner/soma-fm-player (released under MIT licence)
|
* Inspired by https://github.com/rainner/soma-fm-player
|
||||||
|
* (released under MIT licence)
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
_audio: new Audio(),
|
_audio: new Audio(),
|
||||||
_context: null,
|
_context: null,
|
||||||
_source: null,
|
|
||||||
_gain: null,
|
|
||||||
|
|
||||||
// Setup audio routing
|
// Setup audio routing
|
||||||
setupAudio() {
|
setupAudio() {
|
||||||
const AudioContext = window.AudioContext || window.webkitAudioContext
|
this._context = new (window.AudioContext || window.webkitAudioContext)()
|
||||||
this._context = new AudioContext()
|
const source = this._context.createMediaElementSource(this._audio)
|
||||||
this._source = this._context.createMediaElementSource(this._audio)
|
source.connect(this._context.destination)
|
||||||
this._gain = this._context.createGain()
|
|
||||||
|
|
||||||
this._source.connect(this._gain)
|
|
||||||
this._gain.connect(this._context.destination)
|
|
||||||
|
|
||||||
this._audio.addEventListener('canplaythrough', (e) => {
|
this._audio.addEventListener('canplaythrough', (e) => {
|
||||||
this._audio.play()
|
this._audio.play()
|
||||||
})
|
})
|
||||||
@ -29,11 +23,9 @@ export default {
|
|||||||
|
|
||||||
// Set audio volume
|
// Set audio volume
|
||||||
setVolume(volume) {
|
setVolume(volume) {
|
||||||
if (!this._gain) return
|
if (this._audio) {
|
||||||
volume = parseFloat(volume) || 0.0
|
this._audio.volume = Math.min(1, Math.max(0, parseFloat(volume) || 0.0))
|
||||||
volume = volume < 0 ? 0 : volume
|
}
|
||||||
volume = volume > 1 ? 1 : volume
|
|
||||||
this._gain.gain.value = volume
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Play audio source url
|
// Play audio source url
|
||||||
|
Loading…
x
Reference in New Issue
Block a user