fixbug tts(stream) not work on ios safari(17.1+) (#8645)

Co-authored-by: crazywoola <427733928@qq.com>
This commit is contained in:
Likename Haojie 2024-09-23 18:44:24 +08:00 committed by GitHub
parent 11d09a92d0
commit 52da5b16e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,7 @@ export default class AudioPlayer {
mediaSource: MediaSource | null mediaSource: MediaSource | null
audio: HTMLAudioElement audio: HTMLAudioElement
audioContext: AudioContext audioContext: AudioContext
sourceBuffer?: SourceBuffer sourceBuffer?: any
cacheBuffers: ArrayBuffer[] = [] cacheBuffers: ArrayBuffer[] = []
pauseTimer: number | null = null pauseTimer: number | null = null
msgId: string | undefined msgId: string | undefined
@ -33,7 +33,7 @@ export default class AudioPlayer {
this.callback = callback this.callback = callback
// Compatible with iphone ios17 ManagedMediaSource // Compatible with iphone ios17 ManagedMediaSource
const MediaSource = window.MediaSource || window.ManagedMediaSource const MediaSource = window.ManagedMediaSource || window.MediaSource
if (!MediaSource) { if (!MediaSource) {
Toast.notify({ Toast.notify({
message: 'Your browser does not support audio streaming, if you are using an iPhone, please update to iOS 17.1 or later.', message: 'Your browser does not support audio streaming, if you are using an iPhone, please update to iOS 17.1 or later.',
@ -43,6 +43,10 @@ export default class AudioPlayer {
this.mediaSource = MediaSource ? new MediaSource() : null this.mediaSource = MediaSource ? new MediaSource() : null
this.audio = new Audio() this.audio = new Audio()
this.setCallback(callback) this.setCallback(callback)
if (!window.MediaSource) { // if use ManagedMediaSource
this.audio.disableRemotePlayback = true
this.audio.controls = true
}
this.audio.src = this.mediaSource ? URL.createObjectURL(this.mediaSource) : '' this.audio.src = this.mediaSource ? URL.createObjectURL(this.mediaSource) : ''
this.audio.autoplay = true this.audio.autoplay = true