mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
minor (#4795)
This commit is contained in:
@@ -42,6 +42,12 @@ export const AudioType = Enum({
|
||||
UNKNOWN_AUDIO: 3,
|
||||
});
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 音频片段资源,每个片段知道自己应该如何播放、寻址等。
|
||||
* 每当音频片段实际开始播放时,会发出 'started' 事件;
|
||||
* 每当音频片段自然结束播放时,会发出 'ended' 事件。
|
||||
*/
|
||||
@ccclass('cc.AudioClip')
|
||||
export class AudioClip extends Asset {
|
||||
|
||||
@@ -49,22 +55,26 @@ export class AudioClip extends Asset {
|
||||
public static AudioType = AudioType;
|
||||
public static preventDeferredLoadDependents = true;
|
||||
|
||||
@property // we serialize this because it's unavailable at runtime on some platforms
|
||||
protected _duration = 0;
|
||||
@property({
|
||||
type: AudioType,
|
||||
})
|
||||
@property
|
||||
protected _duration = 0; // we serialize this because it's unavailable at runtime on some platforms
|
||||
|
||||
@property({ type: AudioType })
|
||||
protected _loadMode = AudioType.UNKNOWN_AUDIO;
|
||||
|
||||
protected _audio: any = null;
|
||||
private _player: AudioPlayer | null = null;
|
||||
protected _player: AudioPlayer | null = null;
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
this.loaded = false;
|
||||
}
|
||||
|
||||
public set _nativeAsset (clip: any) {
|
||||
public destroy () {
|
||||
if (this._player) { this._player.destroy(); }
|
||||
return super.destroy();
|
||||
}
|
||||
|
||||
set _nativeAsset (clip: any) {
|
||||
this._audio = clip;
|
||||
if (clip) {
|
||||
let ctor: any;
|
||||
@@ -89,15 +99,10 @@ export class AudioClip extends Asset {
|
||||
}
|
||||
}
|
||||
|
||||
public get _nativeAsset () {
|
||||
get _nativeAsset () {
|
||||
return this._audio;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._player) { this._player.destroy(); }
|
||||
return super.destroy();
|
||||
}
|
||||
|
||||
get loadMode () {
|
||||
return this._loadMode;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ export class AudioPlayerWX extends AudioPlayer {
|
||||
/* InnerAudioContext doesn't support multiple playback at the
|
||||
same time so here we fall back to re-start style approach */
|
||||
if (!this._audio) { return; }
|
||||
this._audio.seek(0);
|
||||
this._audio.volume = volume;
|
||||
if (this._oneShoting) { return; }
|
||||
this._audio.loop = false;
|
||||
|
||||
@@ -312,7 +312,7 @@ export class Material extends Asset {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (passIdx >= this._props.length) { console.warn(`illegal pass index: ${passIdx}.`); return; }
|
||||
if (passIdx >= this._props.length) { console.warn(`illegal pass index: ${passIdx}.`); return null; }
|
||||
const props = this._props[passIdx];
|
||||
for (const p of Object.keys(props)) {
|
||||
if (p === name) { return props[p]; }
|
||||
|
||||
@@ -92,7 +92,7 @@ export class AudioSourceComponent extends Component {
|
||||
* @zh
|
||||
* 是否启用自动播放。 <br>
|
||||
* 请注意,根据最新的自动播放策略,现在大部分时候,自动播放只会在第一次收到用户输入后生效。 <br>
|
||||
* @see https://www.chromium.org/audio-video/autoplay
|
||||
* 参考:https://www.chromium.org/audio-video/autoplay
|
||||
*/
|
||||
@property
|
||||
set playOnAwake (val) {
|
||||
@@ -173,8 +173,8 @@ export class AudioSourceComponent extends Component {
|
||||
* 注意,对同一个音频片段,不同平台多重播放效果存在差异。<br>
|
||||
* 在 Web Audio 模式下,可以同时维护多个播放进度,达到多重播放。<br>
|
||||
* 其他模式下都不支持多重播放,如前一次尚未播完,则会立即重新播放。
|
||||
* @param clip - the clip being played
|
||||
* @param volumeScale - the scale of the volume (0-1).
|
||||
* @param clip 要播放的音频
|
||||
* @param volumeScale 相对当前音量的缩放,默认为 1
|
||||
*/
|
||||
public playOneShot (clip: AudioClip, volumeScale = 1) {
|
||||
clip.playOneShot(this._volume * volumeScale);
|
||||
@@ -193,7 +193,7 @@ export class AudioSourceComponent extends Component {
|
||||
* set current playback time, in seconds
|
||||
* @zh
|
||||
* 以秒为单位设置当前播放时间。
|
||||
* @param num the playback time you want to jump to
|
||||
* @param num 要跳转到的播放时间
|
||||
*/
|
||||
set currentTime (num: number) {
|
||||
this._cachedCurrentTime = num;
|
||||
@@ -206,7 +206,6 @@ export class AudioSourceComponent extends Component {
|
||||
* get the current playback time, in seconds
|
||||
* @zh
|
||||
* 以秒为单位获取当前播放时间。
|
||||
* @returns time current playback time
|
||||
*/
|
||||
get currentTime () {
|
||||
if (!this._clip) { return this._cachedCurrentTime; }
|
||||
@@ -217,8 +216,7 @@ export class AudioSourceComponent extends Component {
|
||||
* @en
|
||||
* get the audio duration, in seconds
|
||||
* @zh
|
||||
* 以秒为单位获取音频持续时间。
|
||||
* @returns audio duration
|
||||
* 获取以秒为单位的音频总时长。
|
||||
*/
|
||||
get duration () {
|
||||
if (!this._clip) { return 0; }
|
||||
@@ -230,7 +228,6 @@ export class AudioSourceComponent extends Component {
|
||||
* get current audio state
|
||||
* @zh
|
||||
* 获取当前音频状态。
|
||||
* @returns current audio state
|
||||
*/
|
||||
get state () {
|
||||
if (!this._clip) { return AudioClip.PlayingState.INITIALIZING; }
|
||||
|
||||
@@ -177,11 +177,11 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent {
|
||||
|
||||
public cookMaterials () {
|
||||
const mat = this.getMaterial(0);
|
||||
if (!mat || !this._batchMaterial || !mat.effectAsset) {
|
||||
if (!mat || !this._batchMaterial || !this._batchMaterial.effectAsset) {
|
||||
console.warn('incomplete batch material!'); return;
|
||||
}
|
||||
mat.copy(this._batchMaterial); this.resizeAtlases();
|
||||
const tech = mat.effectAsset.techniques[mat.technique];
|
||||
const tech = mat.effectAsset!.techniques[mat.technique];
|
||||
for (let i = 0; i < tech.passes.length; i++) {
|
||||
const pass = tech.passes[i];
|
||||
if (!pass.properties) { continue; }
|
||||
|
||||
Reference in New Issue
Block a user