1 |
|
2 | __proto.load = function (url, type, cache, group, ignoreCache) {
|
3 | (cache === void 0) && (cache = true);
|
4 | (ignoreCache === void 0) && (ignoreCache = false);
|
5 | this._url = url;
|
6 | if (url.indexOf("data:image") === 0) this._type = type = "image";
|
7 | else {
|
8 | this._type = type || (type = this.getTypeFromUrl(url));
|
9 | url = URL.formatURL(url);
|
10 | }
|
11 | this._cache = cache;
|
12 | this._data = null;
|
13 | if (!ignoreCache && Loader.loadedMap[url]) {
|
14 | this._data = Loader.loadedMap[url];
|
15 | this.event("progress", 1);
|
16 | this.event("complete", this._data);
|
17 | return;
|
18 | }
|
19 | if (group) Loader.setGroup(url, group);
|
20 | if (Loader.parserMap[type] != null) {
|
21 | this._customParse = true;
|
22 | if (((Loader.parserMap[type]) instanceof laya.utils.Handler)) Loader.parserMap[type].runWith(this);
|
23 | else Loader.parserMap[type].call(null, this);
|
24 | return;
|
25 | }
|
26 | if (type === "image" || type === "htmlimage" || type === "nativeimage") return this._loadImage(url);
|
27 | if (type === "sound") return this._loadSound(url);
|
28 | if (type === "ttf") return this._loadTTF(url);
|
29 | var contentType;
|
30 | switch (type) {
|
31 | case "atlas":
|
32 | case "plf":
|
33 | contentType = "json";
|
34 | break;
|
35 | case "font":
|
36 | contentType = "xml";
|
37 | break;
|
38 | case "pkm":
|
39 | contentType = "arraybuffer";
|
40 | break
|
41 | default:
|
42 | contentType = type;
|
43 | }
|
44 |
|
45 | if (qg) {
|
46 | if (url.startsWith('file://'))
|
47 | url = url.substr('file://'.length);
|
48 | var response;
|
49 | var that = this;
|
50 | if (type == 'pkm' || type == 'arraybuffer') {
|
51 | qg.readFile({
|
52 | uri: this._url,
|
53 |
|
54 | encoding: 'binary',
|
55 | success: function (params) {
|
56 | response = params.text;
|
57 | that.onLoaded(response);
|
58 | },
|
59 | fail: function (params) {
|
60 | console.log(params);
|
61 | }
|
62 | });
|
63 | }
|
64 | else {
|
65 | qg.readFile({
|
66 | uri: this._url,
|
67 | encoding: "utf8",
|
68 | success: function (params) {
|
69 | response = params.text;
|
70 | if (type == 'atlas' || type == 'json') {
|
71 | response = JSON.parse(response);
|
72 | }
|
73 | if (type == "xml") {
|
74 | response = (new DOMParser()).parseFromString(response);
|
75 | }
|
76 | that.onLoaded(response);
|
77 | },
|
78 | fail: function (params) {
|
79 | console.log(params);
|
80 | }
|
81 | });
|
82 | }
|
83 | return;
|
84 | }
|
85 |
|
86 | if (Loader.preLoadedMap[url]) {
|
87 | this.onLoaded(Loader.preLoadedMap[url]);
|
88 | } else {
|
89 | if (!this._http) {
|
90 | this._http = new HttpRequest();
|
91 | this._http.on("progress", this, this.onProgress);
|
92 | this._http.on("error", this, this.onError);
|
93 | this._http.on("complete", this, this.onLoaded);
|
94 | }
|
95 | this._http.send(url, null, "get", contentType);
|
96 | }
|
97 | }
|
98 |
|
99 |
|
100 | URL.formatURL = function (url, base) {
|
101 | if (!url) return "null path";
|
102 | if (url.indexOf(":") > 0) return url;
|
103 | if (URL.customFormat != null) url = URL.customFormat(url, base);
|
104 | var char1 = url.charAt(0);
|
105 | if (char1 === ".") {
|
106 | return URL.formatRelativePath((base || URL.basePath) + url);
|
107 | } else if (char1 === '~') {
|
108 | return URL.rootPath + url.substring(1);
|
109 | } else if (char1 === "d") {
|
110 | if (url.indexOf("data:image") === 0) return url;
|
111 | } else if (char1 === "/") {
|
112 | return url;
|
113 | }
|
114 | if (qg) {
|
115 | return (base || 'file://') + url;
|
116 | } else {
|
117 | return (base || URL.basePath) + url;
|
118 | }
|
119 | }
|
120 |
|
121 | if (this.xs != 1 || this.ys != 1){
|
122 | this._ctx.scale(this.xs, this.ys);
|
123 | if(qg){
|
124 | var string = this.font + "";
|
125 | string = string.replace(/\d + /g, '');
|
126 | var mFontSize = parseInt(parseInt(this.font) * ((this.xs > this.ys) ? this.xs : this.ys) + "");
|
127 | this._ctx.font = mFontSize + string + "";
|
128 | }
|
129 | }
|
130 |
|
131 | __getset(0,__proto,'nativeInput',function(){
|
132 | Input.area.blur = Input.input.blur = function(){}
|
133 | return this._multiline ? Input.area :Input.input;
|
134 | });
|
135 |
|
136 | var AudioSound = function (_super) {
|
137 | function AudioSound() {
|
138 | this.url = null;
|
139 | this.audio = null;
|
140 | this.loaded = false;
|
141 | AudioSound.__super.call(this);
|
142 | }
|
143 | __class(AudioSound, 'laya.media.h5audio.AudioSound', _super);
|
144 | var __proto = AudioSound.prototype;
|
145 | __proto.dispose = function () {
|
146 | var ad = AudioSound._audioCache[this.url];
|
147 | if (ad) {
|
148 | ad.src = '';
|
149 | delete AudioSound._audioCache[this.url];
|
150 | }
|
151 | };
|
152 | __proto.load = function (url) {
|
153 | url = URL.formatURL(url);
|
154 | this.url = url;
|
155 | var ad;
|
156 | if (url == SoundManager._tMusic) {
|
157 | AudioSound._initMusicAudio();
|
158 | ad = AudioSound._musicAudio;
|
159 | if (ad.src != url) {
|
160 | AudioSound._audioCache[ad.src] = null;
|
161 | ad = null;
|
162 | }
|
163 | } else {
|
164 | ad = AudioSound._audioCache[url];
|
165 | }
|
166 | if (ad && ad.readyState >= 2) {
|
167 | this.event('complete');
|
168 | return;
|
169 | }
|
170 | if (!ad) {
|
171 | ad = qg.createInnerAudioContext()
|
172 | var src = ""
|
173 | if(/file:\/\//.test(url)){
|
174 | src = url.slice(7)
|
175 | }
|
176 | AudioSound._audioCache[url] = ad;
|
177 | ad.src = src;
|
178 | ad.play()
|
179 | var me = this;
|
180 | let flag = 1
|
181 | while (flag) {
|
182 | if (ad.duration > 0) {
|
183 | me.length = ad.duration
|
184 | me.loaded = true;
|
185 | me.event('complete');
|
186 | ad.stop()
|
187 | flag = 0
|
188 | }
|
189 | }
|
190 | }
|
191 | this.audio = ad;
|
192 | };
|
193 | __proto.play = function (startTime, loops) {
|
194 | startTime === void 0 && (startTime = 0);
|
195 | loops === void 0 && (loops = 0);
|
196 | if (!this.url)
|
197 | return null;
|
198 | var ad;
|
199 | if (this.url == SoundManager._tMusic) {
|
200 | ad = AudioSound._musicAudio;
|
201 | } else {
|
202 | ad = AudioSound._audioCache[this.url];
|
203 | }
|
204 | if (!ad)
|
205 | return null;
|
206 | var tAd;
|
207 | tAd = Pool.getItem('audio:' + this.url);
|
208 | if (Render.isConchApp) {
|
209 | if (!tAd) {
|
210 | tAd = Browser.createElement('audio');
|
211 | tAd.src = this.url;
|
212 | }
|
213 | } else {
|
214 | if (this.url == SoundManager._tMusic) {
|
215 | AudioSound._initMusicAudio();
|
216 | tAd = AudioSound._musicAudio;
|
217 | tAd.src = this.url;
|
218 | } else {
|
219 | tAd = tAd ? tAd : ad.cloneNode(true);
|
220 | }
|
221 | }
|
222 | ;
|
223 | var channel = new AudioSoundChannel(tAd);
|
224 | channel.url = this.url;
|
225 | channel.loops = loops;
|
226 | channel.startTime = startTime;
|
227 | channel.play();
|
228 | SoundManager.addChannel(channel);
|
229 | return channel;
|
230 | };
|
231 | __getset(0, __proto, 'duration', function () {
|
232 | var ad;
|
233 | ad = AudioSound._audioCache[this.url];
|
234 | if (!ad)
|
235 | return 0;
|
236 | return ad.duration;
|
237 | });
|
238 | AudioSound._initMusicAudio = function () {
|
239 | if (AudioSound._musicAudio)
|
240 | return;
|
241 | if (!AudioSound._musicAudio)
|
242 | AudioSound._musicAudio = Browser.createElement('audio');
|
243 | if (!Render.isConchApp) {
|
244 | Browser.document.addEventListener('mousedown', AudioSound._makeMusicOK);
|
245 | }
|
246 | };
|
247 | AudioSound._makeMusicOK = function () {
|
248 | Browser.document.removeEventListener('mousedown', AudioSound._makeMusicOK);
|
249 | if (!AudioSound._musicAudio.src) {
|
250 | AudioSound._musicAudio.src = '';
|
251 | AudioSound._musicAudio.load();
|
252 | } else {
|
253 | AudioSound._musicAudio.play();
|
254 | }
|
255 | };
|
256 | AudioSound._audioCache = {};
|
257 | AudioSound._musicAudio = null;
|
258 | return AudioSound;
|
259 | }(EventDispatcher); |
\ | No newline at end of file |