手动清除或删除 mediaelement.js 播放器
我正在尝试在backbone.js 站点中使用mediaelement.js 播放器,但当我进出我设置的各种路线时,我无法手动删除视频/音频播放器。
假设我的页面上有两个视频。当我离开这个页面时,这两个视频仍然保留在内存中:
> mejs.players
> [object, object]
当我返回页面时,原来的两个视频仍然在内存中,另外两个视频被添加到玩家对象中:
> mejs.players
> [object, object, object, object]
事实上,每次我离开页面然后返回,另外 2 个玩家被添加到 mejs.players
对象中。
有没有办法手动清除/删除所有玩家?
我尝试过以下操作:
mejs.players[0].remove()
这似乎从页面中删除了播放器控件,留下了 HTML5 视频播放器。但是,当我检查 mejs.players
时,播放器仍然存在。我可能是错的,但这对于性能来说似乎并不是最佳的。
I'm attempting to use the mediaelement.js player in a backbone.js site and I'm having trouble removing video/audio players manually when I move in and out of the various routes I have set up.
Let's say I have two videos on my page. When I move away from this page, these two videos are still preserved in memory:
> mejs.players
> [object, object]
When I return to the page, the original two videos are still in memory and an additional 2 videos are added to the players object:
> mejs.players
> [object, object, object, object]
In fact, every time I leave the page and then return, an additional 2 players are added to the mejs.players
object.
Is there a way to clear/remove all of the players manually?
I've tried the following:
mejs.players[0].remove()
This seems to remove the player controls from the page, leaving the HTML5 video player. However, the player still persists when I check mejs.players
. I could be wrong, but this doesn't seem optimal for performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于这是针对 Backbone 站点(具有 UnderscoreJS),因此这可以工作,您可以使用 _.keys() 而不是 Object.keys()
Since this is for a Backbone site (which has UnderscoreJS), this would work, you can use _.keys() instead of Object.keys()
首先删除 mejs.players 并创建新的 mejs.players 数组
if (mejs) {
delete mejs.players;
mejs.players = [];
}
first delete mejs.players and create new mejs.players array
if (mejs) {
delete mejs.players;
mejs.players = [];
}