-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
Rename variables like #9751 Clamp playback rate Add playback rate to one shot audio
Merge html5 playback rate patch manually
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;
/**
|
@@ -304,6 +307,13 @@ export class AudioPlayerMinigame implements OperationQueueable { | |||
val = clamp01(val); | |||
this._innerAudioContext.volume = val; | |||
} | |||
get playbackRate (): number { | |||
return this._innerAudioContext.volume; |
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.
It's a logic error?
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.
Minigame platform need other apps support this feature, and volume should be changed to playbackRate
pal/audio/minigame/player.ts
Outdated
@@ -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; } |
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.
need to check the filed 'playbackRate' exist, as some mini game platforms may not implement this feature
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
Continuous Integration
This pull request:
Compatibility Check
This pull request: