8000 migrate audio bug fix on 2D && support audio clone and AudioManager by PPpro · Pull Request #7192 · cocos/cocos-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 15 commits into from
Oct 19, 2020

Conversation

PPpro
Copy link
Contributor
@PPpro PPpro commented Aug 20, 2020

@PPpro PPpro changed the title try set web audio volume immediately migrate audio bug fix on 2D Aug 20, 2020
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)
Copy link
Contributor Author

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

@PPpro PPpro force-pushed the 3d_audio branch 2 times, most recently from 135ebe8 to 4261ac3 Compare October 14, 2020 09:05
@PPpro PPpro changed the title migrate audio bug fix on 2D migrate audio bug fix on 2D && support audio clone and AudioManager Oct 14, 2020
@PPpro PPpro requested a review from YunHsiao October 14, 2020 09:55
@PPpro PPpro marked this pull request as ready for review October 14, 2020 09:55
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);
Copy link
Contributor

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 这层,这个耳机拔出的问题也可以在那解释就好

Copy link
Contributor Author
@PPpro PPpro Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 用户使用的是 audioClip.play(), 预期的行为应该是怎样的呢,
会导致行为跟 audioSource 不一致吗

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯…也有道理,那你权衡吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者说我们应该禁止用户使用 audioClip 去播放音频 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恐怕做不到,总有封装不到的时候,只能引导说尽量用 audio source

@@ -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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确定这么做性能吃得消?还是说给用户个选择,加个 forceMultitrack 之类的开关

Copy link
Contributor Author

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 这块就不太好处理

Copy link
Contributor Author
@PPpro PPpro Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对了,这里的 audioClip 封顶就 24 个了,多了会被停止播放留待gc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

噢要把 one shot 的东西也管理起来是吧,是否考虑更细粒度的做法,在每个 player 后端里管理各自的东西?这样分了后端又引用回上层的设计感觉挺不好的

let clip = new AudioClip();
clip._nativeAsset = this._nativeAudio;
resolve(clip);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone 需要放在 player 层吗,还是 clip 自己 clone 就行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里其实 clone() 应该改成 spawnAndPlayNativeAudio 会好一点,,,名字长了点

Copy link
Contributor
@YunHsiao YunHsiao Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还是类似的问题,从底层回去引用上层总感觉是不太好的设计。一定要有个类似的东西的话,那也应该是返回一个新的 player,或 nativeAudio 才对

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白

@@ -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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

噢要把 one shot 的东西也管理起来是吧,是否考虑更细粒度的做法,在每个 player 后端里管理各自的东西?这样分了后端又引用回上层的设计感觉挺不好的

@PPpro
Copy link
Contributor Author
PPpro commented Oct 14, 2020

嗯,可以考虑更细粒度的 manager,现在的 manager 确实没有区分后端,之后修复平台问题可能还要做各种 HACK。。。

@PPpro
Copy link
Contributor Author
PPpro commented Oct 16, 2020

pr 更新了,麻烦 @YunHsiao 有空再 review 一下

@PPpro PPpro merged commit baf39c5 into cocos:3d Oct 19, 2020
@PPpro PPpro deleted the 3d_audio branch October 19, 2020 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0