Chimeejs / chimee

a video player framework aims to bring wonderful experience on browser
http://chimee.pyzy.net/
MIT License
2.4k stars 201 forks source link

require([],func) 异步方式 引入某插件模块,然后Chimee.install 但实际是没有安装成功 #141

Closed westdrug closed 6 years ago

westdrug commented 6 years ago

如上标题,如下代码:

require(['chimee-plugin-danmu'], function(chimeePluginDanmu) { console.log('chimeePluginDanmu',chimeePluginDanmu) Chimee.install(chimeePluginDanmu) })

插件异步引入成功,然后安装插件 Chimee.install(chimeePluginDanmu),但没有安装成功。

版本如下:

chimee v0.9.5

chimee-plugin-danmu v0.0.8

寻求帮助,谢啦!

toxic-johann commented 6 years ago

建议均升级到最新版再看看能否复现。

westdrug commented 6 years ago

@toxic-johann 你好, 升级版本:

chimee-player v1.4.5;
chimee-plugin-danmu v0.0.9, 

还是异步加载后,没有安装成功。 使用 chimee.use 后 报错为:

Uncaught TypeError: You have not installed plugin chimeeDanmu

toxic-johann commented 6 years ago

输出一下这个变量 chimeePluginDanmu

另外 use 是怎么写的

westdrug commented 6 years ago

@toxic-johann 输出chimeePluginDanmu 如下图: 1111

此处代码:

require(['chimee-plugin-danmu'], function(chimeePluginDanmu) { console.log('chimeePluginDanmu',chimeePluginDanmu) Chimee.install(chimeePluginDanmu) Chimee.use(chimeePluginDanmu.name) })

—————————————————————————————————————— use 应该是 实例化后调用?, player.use('chimeeDanmu') 此时报了个错误:

Uncaught TypeError: You have not installed plugin chimeeDanmu

也就是说: 使用 require([],func) 异步方式 引入插件,并安装插件。是在 实例化之后才进行的,所以会报: 没有安装 plugin chimeeDanmu

这是我的理解。

toxic-johann commented 6 years ago

use 是实例化后的 chimee install 是 Chimee 静态对象。现在两个为啥是一样的? player.use(chimeePluginDanmu.name)

westdrug commented 6 years ago

是的, 应该在 实例化后 执行 player.use('chimeeDanmu') 但此时报了个错误:

Uncaught TypeError: You have not installed plugin chimeeDanmu

猜想: 使用 require([],func) 异步方式 引入插件,并安装插件。是在 实例化之后才进行的,异步加载并安装比 player.use('chimeeDanmu') 执行过程 还要迟

toxic-johann commented 6 years ago

https://github.com/Chimeejs/chimee/blob/master/doc/zh-cn/api/chimee-api.md#%E6%8F%92%E4%BB%B6%E6%93%8D%E4%BD%9C

用 hasInstalled 查看一下。最好看下能不能提供个类似 codepen 之类的环境。现在你的描述我们这边复现不出来。

westdrug commented 6 years ago

@toxic-johann 好,我再自查下,谢谢了!

westdrug commented 6 years ago

@toxic-johann 你好,今早看了下, install 后, hasInstalled 没有输出 true或false; use 加了延时, 并打印出 实例化对象中的 $plugins插件集合 里面是包含有 异步加载后并安装的那个插件,并报如下错误: image

yandeqiang commented 6 years ago

这是弹幕插件的一个bug 已经修了。 更新一下 chimee-plugin-danmu

westdrug commented 6 years ago

@toxic-johann @yandeqiang 可以了!

但: require([],func) 用按需的方式引入 插件模块, 因为模块异步加载,在未加载完成,并未安装时,就已经执行了player.use(), 会报 :

Uncaught TypeError: You have not installed plugin xxx

use 用了 延时,才能正常使用, 但这不是想要的。暂时没有想到改进的办法!

toxic-johann commented 6 years ago

你没安装肯定没法用啊。。。。这个是业务逻辑需要解决的吧