如何使 `just_audio` 在 Flutter 中不中断后台正在播放的音频?

huangapple go评论76阅读模式
英文:

How to make `just_audio` not interrupt the playback of whatever audio is playing in the background in Flutter?

问题

我正在使用just audio package在我的Flutter应用中播放1秒钟的蜂鸣声,主要面向iOS。

我遇到的问题是,当播放这个蜂鸣声时,其他音频(音乐、有声读物等)会停止播放,而且停止后不会自动恢复。

是否有一种方法可以在蜂鸣声播放1秒钟时,只将背景音乐的声音降低50%,然后恢复正常播放?

英文:

I'm using just audio package to play 1-second beeping sounds in my Flutter app which is aimed mainly at iOS.

The problem I'm having is that other audio (music, audiobooks, etc) is stopped whenever this beep sound gets played and it stays stopped, i.e. it doesn't resume automatically after the beep.

Is there a way to just reduce the sound of the background audio by, say 50% for that 1 second the beep is going to take and then resume the normal playback?

答案1

得分: 1

你可以使用以下包: just_audio 0.9.32audio_session 0.1.13

just_audio 是一个音频播放器,而 audio_session 用于控制音频设置,即在播放哔哔声时以及哔哔声播放完成后,audio_session 会恢复先前的音频设置。

你可以使用 "setCategoryVolumeGain" 方法将音量降低50%,在哔哔声播放后,先前的音频会自动恢复。

英文:

You can use the packages : just_audio 0.9.32 and audio_session 0.1.13

just_audio is an audio player and audio_session would be used to control the audio settings i.e when the beep sound is played and as it finished the audio_session would restore the previous audio after the beep sound finishes.

You can use the "setCategoryVolumeGain" method to reduce the volume by 50% and when the beep is played after it , it would play and the previous audio would automaticall restore after the beep.

huangapple
  • 本文由 发表于 2023年5月13日 12:44:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定