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

Audio playrate - support oalsoft, update html5 #16764

Closed
wants to merge 6 commits into from
Closed

Audio playrate - support oalsoft, update html5 #16764

wants to merge 6 commits into from

Conversation

lampysprites
Copy link

@lampysprites lampysprites commented Feb 29, 2024

Hello! This code extends playback rate implementation by mikecoker to windows native platform (planned in #10545). Since the original PR no longer merges properly with upstream, I took liberty to do that manually.

I do not have much understanding of mobile development to finish this on my own, unfortunately. However I did check that compilation of android project is not affected by these changes.

Changelog

  • Add playback rate to native audio player and one shot audio player
  • Update and merge playback rate html5 code from Audio playrate #9751, including requested edits to it (except comments translation, because they changed in some places anyway)
  • Change headers for android and apple for compatibility. Playback rate value is ignored on that platform.

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.

lampysprites and others added 4 commits February 29, 2024 16:11
Copy link

github-actions bot commented Feb 29, 2024

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -7425,9 +7425,9 @@
         stop(): void;
         /**
          * @deprecated since v3.1.0, please use AudioSource.prototype.playOneShot() instead.
          */
-        playOneShot(volume?: number): void;
+        playOneShot(volume?: number, playbackRate?: number): void;
     }
     /**
      * @en
      * A representation of a single audio source, <br>
@@ -7443,8 +7443,9 @@
         protected _player: __private._pal_audio__AudioPlayer | null;
         protected _loop: boolean;
         protected _playOnAwake: boolean;
         protected _volume: number;
+        protected _playbackRate: number;
         /**
          * @en
          * The default AudioClip to be played for this audio source.
          * @zh
@@ -7482,8 +7483,18 @@
          * 请注意,在某些平台上,音量控制可能不起效。<br>
          */
         set volume(val: number);
         get volume(): number;
+        /**
+         * @en
+         * The playback rate of this audio source (0.0 to 10.0).<br>
+         * Note: Playback rate is only supported on Web, Windows, and ByteDance for now.
+         * @zh
+         * 此音频源的播放速率(0.0 到 10.0)。<br>
+         * 注意:播放速率在某些平台上可能无效。<br>
+         */
+        set playbackRate(val: number);
+        get playbackRate(): number;
         onLoad(): void;
         onEnable(): void;
         onDisable(): void;
         onDestroy(): void;
@@ -7559,15 +7570,18 @@
          */
         stop(): void;
         /**
          * @en
-         * Plays an AudioClip, and scales volume by volumeScale. The result volume is `audioSource.volume * volumeScale`. <br>
+         * Plays an AudioClip, and scales volume and playback rate by volumeScale and playbackRateScale
+         * respectively. The result volume is `audioSource.volume * volumeScale`, the result playback
+         * rate is `audioSource.playbackRate * playbackRateScale`
          * @zh
          * 以指定音量倍数播放一个音频一次。最终播放的音量为 `audioSource.volume * volumeScale`。 <br>
          * @param clip The audio clip to be played.
          * @param volumeScale volume scaling factor wrt. current value.
+         * @param playbackRateScale playback rate scaling factor wrt. current value.
          */
-        playOneShot(clip: AudioClip, volumeScale?: number): void;
+        playOneShot(clip: AudioClip, volumeScale?: number, playbackRateScale?: number): void;
         protected _syncStates(): void;
         /**
          * @en
          * Set current playback time, in seconds.
@@ -61381,9 +61395,9 @@
              * @param volume Specify the volume.
              * @param opts Load options.
              * @returns The OneShotAudio instance.
              */
-            static loadOneShotAudio(url: string, volume: number, opts?: import('pal/audio/type').AudioLoadOptions): Promise<_pal_audio__OneShotAudio>;
+            static loadOneShotAudio(url: string, volume: number, playbackRate: number, opts?: import('pal/audio/type').AudioLoadOptions): Promise<_pal_audio__OneShotAudio>;
             /**
              * Max audio channel count allowed on current platform.
              * If the amount of playing audios exceeds the limit,
              * some audio instances would be discarded by audio manager.
@@ -61413,8 +61427,13 @@
              */
             get volume(): number;
             set volume(val: number);
             /**
+             * get or set current playback rate of this player, ranged from 0 to 10, default is 1.
+             */
+            get playbackRate(): number;
+            set playbackRate(val: number);
+            /**
              * The duration of this audio player.
              */
             get duration(): number;
             /**

@lampysprites lampysprites marked this pull request as draft February 29, 2024 13:21
@minggo minggo requested a review from bofeng-song March 5, 2024 02:14
@@ -304,6 +307,13 @@ export class AudioPlayerMinigame implements OperationQueueable {
val = clamp01(val);
this._innerAudioContext.volume = val;
}
get playbackRate (): number {
return this._innerAudioContext.volume;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a logic error?

Copy link
Contributor

@bofeng-song bofeng-song Mar 6, 2024

Choose a reason for hiding this comment

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

Minigame platform need other apps support this feature, and volume should be changed to playbackRate

@@ -110,6 +110,8 @@ export class AudioPlayer {
set loop (val: boolean) { this._player.loop = val; }
get volume (): number { return this._player.volume; }
set volume (val: number) { this._player.volume = val; }
get playbackRate (): number { return this._player.playbackRate; }
set playbackRate (val: number) { this._player.playbackRate = val; }
Copy link
Contributor

Choose a reason for hiding this comment

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

need to check the filed 'playbackRate' exist, as some mini game platforms may not implement this feature

@lampysprites lampysprites closed this by deleting the head repository Apr 21, 2024
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