mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 12:15:54 +08:00
fix(player): release object urls (#1121)
This commit is contained in:
parent
d049eb4903
commit
836b7d0ce9
|
@ -38,6 +38,14 @@ export default class {
|
||||||
this._personalFMTrack = { id: 0 }; // 私人FM当前歌曲
|
this._personalFMTrack = { id: 0 }; // 私人FM当前歌曲
|
||||||
this._personalFMNextTrack = { id: 0 }; // 私人FM下一首歌曲信息(为了快速加载下一首)
|
this._personalFMNextTrack = { id: 0 }; // 私人FM下一首歌曲信息(为了快速加载下一首)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The blob records for cleanup.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @type {string[]}
|
||||||
|
*/
|
||||||
|
this.createdBlobRecords = [];
|
||||||
|
|
||||||
// howler (https://github.com/goldfire/howler.js)
|
// howler (https://github.com/goldfire/howler.js)
|
||||||
this._howler = null;
|
this._howler = null;
|
||||||
Object.defineProperty(this, '_howler', {
|
Object.defineProperty(this, '_howler', {
|
||||||
|
@ -247,7 +255,21 @@ export default class {
|
||||||
_getAudioSourceFromCache(id) {
|
_getAudioSourceFromCache(id) {
|
||||||
return getTrackSource(id).then(t => {
|
return getTrackSource(id).then(t => {
|
||||||
if (!t) return null;
|
if (!t) return null;
|
||||||
|
|
||||||
|
// Create a new object URL.
|
||||||
const source = URL.createObjectURL(new Blob([t.source]));
|
const source = URL.createObjectURL(new Blob([t.source]));
|
||||||
|
|
||||||
|
// Clean up the previous object URLs since we've created a new one.
|
||||||
|
// Revoke object URLs can release the memory taken by a Blob,
|
||||||
|
// which occupied a large proportion of memory.
|
||||||
|
for (const url in this.createdBlobRecords) {
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then, we replace the createBlobRecords with new one with
|
||||||
|
// our newly created object URL.
|
||||||
|
this.createdBlobRecords = [source];
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user