lyb-pixi-js 1.1.20 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Utils/LibPixiAudio.d.ts +1 -4
- package/Utils/LibPixiAudio.js +39 -49
- package/lyb-pixi.js +155 -137
- package/package.json +5 -1
package/Utils/LibPixiAudio.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import "@pixi/sound";
|
|
2
|
-
/** @description 音频播放器
|
|
3
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
|
|
4
|
-
*/
|
|
5
2
|
export declare class LibPixiAudio {
|
|
6
3
|
/** 是否启用音效 */
|
|
7
4
|
effectEnabled: boolean;
|
|
@@ -12,7 +9,7 @@ export declare class LibPixiAudio {
|
|
|
12
9
|
/** 是否已切换后台 */
|
|
13
10
|
private _isBackground;
|
|
14
11
|
/** 当前音乐播放器 */
|
|
15
|
-
private _musicPlayer
|
|
12
|
+
private _musicPlayer?;
|
|
16
13
|
/** 当前正在播放的音效列表 */
|
|
17
14
|
private _playingList;
|
|
18
15
|
constructor();
|
package/Utils/LibPixiAudio.js
CHANGED
|
@@ -7,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import gsap from "gsap";
|
|
11
10
|
import { Assets } from "pixi.js";
|
|
11
|
+
import { Howl } from "howler";
|
|
12
12
|
import "@pixi/sound";
|
|
13
|
-
|
|
14
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
|
|
15
|
-
*/
|
|
13
|
+
import gsap from "gsap";
|
|
16
14
|
export class LibPixiAudio {
|
|
17
15
|
constructor() {
|
|
18
16
|
/** 是否启用音效 */
|
|
@@ -45,7 +43,6 @@ export class LibPixiAudio {
|
|
|
45
43
|
}
|
|
46
44
|
});
|
|
47
45
|
};
|
|
48
|
-
this._musicPlayer = new Audio();
|
|
49
46
|
document.addEventListener("visibilitychange", () => {
|
|
50
47
|
this._isBackground = document.hidden;
|
|
51
48
|
this._setPlayStatus(!document.hidden);
|
|
@@ -59,28 +56,26 @@ export class LibPixiAudio {
|
|
|
59
56
|
return new Promise((resolve) => {
|
|
60
57
|
const id = new Date().getTime();
|
|
61
58
|
const url = Assets.get(key).url;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const sound = new Howl({
|
|
60
|
+
src: url,
|
|
61
|
+
mute: this._isBackground || !this.effectEnabled,
|
|
62
|
+
});
|
|
63
|
+
sound.play();
|
|
64
|
+
sound.on("end", () => {
|
|
65
65
|
this._playingList = this._playingList.filter((item) => item.id !== id);
|
|
66
66
|
resolve();
|
|
67
67
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
audio,
|
|
80
|
-
url,
|
|
81
|
-
});
|
|
82
|
-
})
|
|
83
|
-
.catch(() => { });
|
|
68
|
+
//倒数几秒位置播放
|
|
69
|
+
if (end) {
|
|
70
|
+
const duration = sound.duration();
|
|
71
|
+
const start = duration - end;
|
|
72
|
+
sound.seek(start);
|
|
73
|
+
}
|
|
74
|
+
this._playingList.push({
|
|
75
|
+
id,
|
|
76
|
+
audio: sound,
|
|
77
|
+
url,
|
|
78
|
+
});
|
|
84
79
|
});
|
|
85
80
|
}
|
|
86
81
|
/** @description 播放音乐
|
|
@@ -88,7 +83,7 @@ export class LibPixiAudio {
|
|
|
88
83
|
*/
|
|
89
84
|
playMusic(key) {
|
|
90
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
|
|
86
|
+
const url = Assets.get(key).url;
|
|
92
87
|
//如果有音乐正在播放,则停止
|
|
93
88
|
if (this._musicPlayer) {
|
|
94
89
|
gsap.killTweensOf(this._musicPlayer);
|
|
@@ -97,29 +92,23 @@ export class LibPixiAudio {
|
|
|
97
92
|
duration: 1,
|
|
98
93
|
ease: "linear",
|
|
99
94
|
});
|
|
100
|
-
|
|
95
|
+
this._musicPlayer.stop();
|
|
101
96
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
.catch(() => {
|
|
119
|
-
requestAnimationFrame(play.bind(this));
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
play();
|
|
97
|
+
this._musicPlayer = new Howl({
|
|
98
|
+
src: url,
|
|
99
|
+
loop: true,
|
|
100
|
+
volume: 0,
|
|
101
|
+
html5: true,
|
|
102
|
+
mute: this._isBackground || !this.effectEnabled,
|
|
103
|
+
});
|
|
104
|
+
this._musicPlayer.play();
|
|
105
|
+
this._isMusicPaused = false;
|
|
106
|
+
gsap.killTweensOf(this._musicPlayer);
|
|
107
|
+
gsap.to(this._musicPlayer, {
|
|
108
|
+
volume: 1,
|
|
109
|
+
duration: 1,
|
|
110
|
+
ease: "linear",
|
|
111
|
+
});
|
|
123
112
|
});
|
|
124
113
|
}
|
|
125
114
|
/** @description 暂停音乐 */
|
|
@@ -164,14 +153,15 @@ export class LibPixiAudio {
|
|
|
164
153
|
* @param disabled 静音状态,true为静音
|
|
165
154
|
*/
|
|
166
155
|
_setMusicMute(disabled) {
|
|
167
|
-
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.mute(disabled || !this.musicEnabled);
|
|
168
158
|
}
|
|
169
159
|
/** @description 设置静音音效
|
|
170
160
|
* @param disabled 静音状态,true为静音
|
|
171
161
|
*/
|
|
172
162
|
_setEffectMute(disabled) {
|
|
173
163
|
this._playingList.forEach((item) => {
|
|
174
|
-
item.audio.
|
|
164
|
+
item.audio.mute(disabled || !this.effectEnabled);
|
|
175
165
|
});
|
|
176
166
|
}
|
|
177
167
|
}
|