-
Notifications
You must be signed in to change notification settings - Fork 2k
migrate audio bug fix on 2D && support audio clone and AudioManager #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cocos/audio/assets/player-web.ts
Outdated
if (this._blocking || this._context.state !== 'running') { | ||
this._interrupted = true; | ||
if ('interrupted' === this._context.state as any && this._context.resume) { | ||
if (('interrupted' === this._context.state as any || 'suspended' === this._context.state as any) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context suspended after unpluging earphone
135ebe8
to
4261ac3
Compare
update update
destroy clip on ended when playing one shot rename var audio clone
cocos/audio/assets/clip.ts
Outdated
especially when player unplug earphones and the audio automatically stops | ||
so we need to force updating the playing state by pausing audio */ | ||
this._player.pause(); | ||
this._player.setCurrentTime(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
设计上 player 这层函数功能都是比较直接的,play 就是 play,如果正在播了就啥也不做,多次调用 play 就从头开始这种存粹的逻辑层封装最好还是放在 audio source 这层,这个耳机拔出的问题也可以在那解释就好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果 用户使用的是 audioClip.play(), 预期的行为应该是怎样的呢,
会导致行为跟 audioSource 不一致吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯…也有道理,那你权衡吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
或者说我们应该禁止用户使用 audioClip 去播放音频 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恐怕做不到,总有封装不到的时候,只能引导说尽量用 audio source
cocos/audio/assets/player.ts
Outdated
@@ -72,7 +73,16 @@ export abstract class AudioPlayer { | |||
public abstract play (): void; | |||
public abstract pause (): void; | |||
public abstract stop (): void; | |||
public abstract playOneShot (volume: number): void; | |||
public playOneShot (volume = 1) { | |||
this._clip.clone().then(clonedClip => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确定这么做性能吃得消?还是说给用户个选择,加个 forceMultitrack 之类的开关
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里确实会有一些性能开销,
其实这么做有一个原因是,audioManager 都统一管理的 audioClip,如果 playOneShot 只产出一个 audioBufferSourceNode, manager 这块就不太好处理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对了,这里的 audioClip 封顶就 24 个了,多了会被停止播放留待gc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
噢要把 one shot 的东西也管理起来是吧,是否考虑更细粒度的做法,在每个 player 后端里管理各自的东西?这样分了后端又引用回上层的设计感觉挺不好的
cocos/audio/assets/player-web.ts
Outdated
let clip = new AudioClip(); | ||
clip._nativeAsset = this._nativeAudio; | ||
resolve(clip); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clone 需要放在 player 层吗,还是 clip 自己 clone 就行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里其实 clone() 应该改成 spawnAndPlayNativeAudio 会好一点,,,名字长了点
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是类似的问题,从底层回去引用上层总感觉是不太好的设计。一定要有个类似的东西的话,那也应该是返回一个新的 player,或 nativeAudio 才对
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
明白
cocos/audio/assets/player.ts
Outdated
@@ -72,7 +73,16 @@ export abstract class AudioPlayer { | |||
public abstract play (): void; | |||
public abstract pause (): void; | |||
public abstract stop (): void; | |||
public abstract playOneShot (volume: number): void; | |||
public playOneShot (volume = 1) { | |||
this._clip.clone().then(clonedClip => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
噢要把 one shot 的东西也管理起来是吧,是否考虑更细粒度的做法,在每个 player 后端里管理各自的东西?这样分了后端又引用回上层的设计感觉挺不好的
嗯,可以考虑更细粒度的 manager,现在的 manager 确实没有区分后端,之后修复平台问题可能还要做各种 HACK。。。 |
pr 更新了,麻烦 @YunHsiao 有空再 review 一下 |
re:
https://github.com/cocos-creator/3d-tasks/issues/4004
https://github.com/cocos-creator/3d-tasks/issues/4013
https://github.com/cocos-creator/3d-tasks/issues/3540
related pr: cocos-creator-packages/adapters#183
changeLog:
add Edge browser type && fix webAudio bug on Edge and Baidu browser #4910 fix webaduio.setTargetTime on crosswalk #5281)