Skip to content
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

refine: erase unneed audio operation & fix potential bug #15884

Merged
merged 6 commits into from
Aug 10, 2023

Conversation

bofeng-song
Copy link
Contributor

Re: # https://github.com/cocos/3d-tasks/issues/7318

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

cocos/audio/audio-source.ts Outdated Show resolved Hide resolved
@@ -38,6 +38,11 @@ enum AudioSourceEventType {
ENDED = 'ended',
}

class OperationInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

where we used this class, can we use the OperationInfo exported from operation-queue.ts ? or should it be an interface ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used by _operationsBeforeLoading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AudioSource only needs two variables, a function name and a parameter; it does not require as many parameter requirements as operation-queue.

Copy link
Contributor

@PPpro PPpro Aug 8, 2023

Choose a reason for hiding this comment

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

could it be an interface instead of a class, I see you only use it as an interface, which is only a type
but class will exist in runtime

pal/audio/operation-queue.ts Outdated Show resolved Hide resolved
instance._operationQueue.splice(index, 1);
});
instance._operationQueue.forEach((opInfo): void => {
instance._eventTarget.emit(opInfo.id.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

this emit message means the operation is finished, are you sure ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I known, what potential problems will it cause?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, only the play interface has a then processing.
this.node?.emit(AudioSourceEventType.STARTED, this);

Copy link
Contributor

@PPpro PPpro Aug 8, 2023

Choose a reason for hiding this comment

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

we only emit the finished message when the operation is finished, see the line no 49

opInfo.func.call(target, ...opInfo.args).then(() => {
opInfo.invoking = false;
target._operationQueue.shift();
target._eventTarget.emit(opInfo.id.toString());
const nextOpInfo: OperationInfo = target._operationQueue[0];
nextOpInfo && _tryCallingRecursively(target, nextOpInfo);
}).catch((e) => {});

Otherwise, the call order of the queue will be messed up.

cocos/audio/audio-source.ts Outdated Show resolved Hide resolved
this._operationsBeforeLoading.forEach((opInfo): void => {
if (opInfo.op === 'seek') {
this._cachedCurrentTime = opInfo.params as number;
this._player?.seek(this._cachedCurrentTime).catch((e): void => {});
Copy link
Contributor

Choose a reason for hiding this comment

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

_player? -> _player as it is checked in if condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

And please fix the ESLint error.

@minggo
Copy link
Contributor

minggo commented Aug 7, 2023

It is better to use state machine for these operations in future.

cocos/audio/audio-source.ts Outdated Show resolved Hide resolved
cocos/audio/audio-source.ts Outdated Show resolved Hide resolved
cocos/audio/audio-source.ts Outdated Show resolved Hide resolved
@minggo minggo merged commit 6b80095 into cocos:v3.8.1 Aug 10, 2023
10 checks passed
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.

3 participants