Giter Site home page Giter Site logo

chimeejs / chimee Goto Github PK

View Code? Open in Web Editor NEW
2.4K 54.0 201.0 10.52 MB

a video player framework aims to bring wonderful experience on browser

Home Page: http://chimee.pyzy.net/

License: MIT License

JavaScript 51.82% Shell 0.02% HTML 42.27% TypeScript 5.89%
video framework flv hls mp4 html5 html5-video html5-video-player video-player h5-video

chimee's Introduction

Chimee

Build Status Coverage Status npm dependency Status devDependency Status tested with jest jest Code Quality: Javascript Total Alerts Greenkeeper badge

English | 中文

Introduction

Chimee is a web video player created by the Qiwoo Team. It's based on the web video element. It supports multiple media streams, including mp4, m3u8, flv, etc.

In most situations, we need to support complex functions based on video, such as many videos or advertising. It's hard to maintain them if you we just write it based on the video element. So we may need to have an iframe to sort out the logic and handle the communication. So Chimee offers a plugin system, so that anyone can split your complex functions into multiple plugins. Through this method of development, developers can decouple logic to achieve a quicker, gray-scale release and implement many other functions with relative ease.

Chimee helps developer to reach complex video capabilities from scratch easier and quicker.

Features

Chimee is a web video player.

  1. It supports multiple video stream including mp4, m3u8, flv, and more.
  2. It solves most of the compatibility problems including cross-browser fullscreen, autoplay, and playing inline.

What's more, it's also a component framework based on the video element.

  1. It helps us to split complex functions off into multiple plugins.
  2. Each plugin can work on the video element directly and easily.
  3. This framework sorts out the hierarchical relationship between plugins, which will keep us free from the z-index problem.
  4. It provides a variety of modules such as a transparent plugin, a penetrating plugin, an inner plugin, and an outer plugin, which will cover most of the interactive scenarios.
  5. It offers us convenient ways to communicate between plugins.
  6. It allows us to define plugin priority, which has been useful in making the advertising plugin work as expected.
  7. It also supports asynchronous plugins.

Installation

npm

npm install --save chimee

cdn

You can get the cdn url on https://cdnjs.com/libraries/chimee.

If you are in china, you can get the cdn url on https://www.jsdelivr.com/package/npm/chimee.

Usage

You can use Chimee directly.

Assuming you have a div whose id is wrapper:

<body>
  <div id="wrapper">
  </div>
</body>

You can then setup Chimee on it:

import Chimee from 'chimee';
const chimee = new Chimee('#wrapper');
chimee.on('play', () => console.log('play!!'));
chimee.load('http://cdn.toxicjohann.com/lostStar.mp4');
chimee.play(); // play!!

Sometimes we need more customization; Chimee can be called by passing in an object:

import Chimee from 'chimee';
const chimee = new Chimee({
  wrapper: '#wrapper',
  src: 'http://cdn.toxicjohann.com/lostStar.mp4',
  controls: true,
  autoplay: true,
});

If you need to play video in flv or hls, you can simply add those kernels:

import Chimee from 'chimee';
import flv from 'chimee-kernel-flv';
import hls from 'chimee-kernel-hls';
const chimee = new Chimee({
  wrapper: '#wrapper',
  src: 'http://cdn.toxicjohann.com/lostStar.mp4',
  controls: true,
  autoplay: true,
  kernels: {
    flv,
    hls
  }
});
chimee.play();

Or you can try installKernel, and then use it:

import Chimee from 'chimee';
import flv from 'chimee-kernel-flv';
import hls from 'chimee-kernel-hls';
Chimee.installKernel(flv);
Chimee.installKernel(hls);
const chimee = new Chimee({
  wrapper: '#wrapper',
  src: 'http://cdn.toxicjohann.com/lostStar.mp4',
  controls: true,
  autoplay: true,
  kernels: [ 'flv', 'hls' ],
});
chimee.play();

If you want to know more about Chimee, please read more on our API docs, here.

However, if you use Chimee directly, it's best to add this style to your page:

container {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}
video {
  width: 100%;
  height: 100%;
  display: block;
  background-color: #000;
}
video:focus,
video:active {
  outline: none;
}

Chimee will simply use the default styles of browsers if you do not use any plugins. But you may want to try our UI plugin…

import popup from 'chimee-plugin-popup';
import Chimee from 'chimee';
Chimee.install(popup);
const chimee = new Chimee({
  wrapper: '#wrapper',
  src: 'http://cdn.toxicjohann.com/lostStar.mp4',
  plugin: [popup.name],
  controls: false,
  autoplay: true
});

If you want to know more about Chimee's plugins, please read more here.

If you don't want more capabilities, and just need a useful video player, you can install chimee-player, which contains the base ui and a loggerL

import ChimeePlayer from 'chimee-player';

const chimee = new ChimeePlayer({
  wrapper: '#wrapper',
  src: 'http://cdn.toxicjohann.com/lostStar.mp4',
  controls: false,
  autoplay: true
});

FAQ

TODO: more coming soon!~

  1. What is Chimee?
  2. What is Chimee's plugin?
  3. How do I write a plugin?
  4. How do I write an advertising plugin??
  5. How do I write a UI plugin?

Explanation of Different Builds

You will find four different builds in the lib.

Name Kind Meaning Define environment?
index.js commonjs Common javascript, mostly used in Webpack 1. Yes
index.mjs esmodule An es module, mostly used in Webpack 2 and rollup. Yes
index.browser.js umd Can be used directly in browser No (It's in development)
index.min.js umd Can be used directly in browser No (It's in production)
Index.esm.js esmodule An es module, mostly used in browser es module No (It's in development)

Development

Development/production modes are hard-coded for the UMD builds: the un-minified files are for development, and the minified files are for production.

CommonJS and ES Module builds are intended for bundlers, therefore we don’t provide minified versions for them. Developers are be responsible for minifying the final bundle themselves.

CommonJS and ES Module builds also preserve raw checks for process.env.NODE_ENV to determine the mode they should run in. Developers should use appropriate bundler configurations to replace these environment variables in order to control which mode Vue will run in. Replacing process.env.NODE_ENV with string literals also allows minifiers like UglifyJS to completely drop the development-only code blocks, agressively reducing final file size.

Webpack

Use Webpack’s DefinePlugin:

var webpack = require('webpack')

module.exports = {
  // ...
  plugins: [
    // ...
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('production')
      }
    })
  ]
}

Rollup

Use rollup-plugin-replace:

const replace = require('rollup-plugin-replace')

rollup({
  // ...
  plugins: [
    replace({
      'process.env.NODE_ENV': JSON.stringify('production')
    })
  ]
}).then(...)

Contribution

Install this project

npm install
npm start

Then open http://127.0.0.1:10001/demo/base/index.html

You can choose another page as you want

Changelog

Please read the release notes.

License

MIT

Please read the release notes.

Donation

You can donate to us through Alipay. That will keep us moving.

image

chimee's People

Contributors

greenkeeper[bot] avatar huzunjie avatar itibbers avatar microj avatar skyline0705 avatar songguangyu avatar toxic-johann avatar travisbuddy avatar xcorail avatar yandeqiang avatar zhaofinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chimee's Issues

连续动态切流两次新的video中poster会设置为当前页面URL

第一次热切换 video 属性复制会默认<video poster ...>,这时再切流复制video属性会读到poster为空字符串,设置给新的videoElement后浏览器将空字串会解析为当前页URL

复现场景:http://chimee.org/demo/live-clarity.html

系统环境: MAC Chrome 62.0.3202.94

相关代码:

if (key !== 'src') this.videoConfig[key] = originVideoConfig[key];

需要增加判断,避免默认值为空时被置为空字串-从而导致浏览器解析为当前页URL。

少了一个n

chimee/src/vessel/vessel.js
line 4: // base css controller for cotainer and wrapper

Should we support `fullscreen` on IE9 and how?

Fullsceeen API is only supported by IE11 and beyond.
But we mark the whole chimee player to IE9.
So should we support fullscreen on IE9? And how?

@yandeqiang offer me code below

if(window.ActiveXObject) {
  const wscript = new window.ActiveXObject('WScript.Shell');
  if(wscript !== null) {
      wscript.SendKeys('{F11}');
  }
}

It's simulate people tapping on F11. And we can exit fullscreen mode in the same way.

But we can't know whether the page is fullscreen or not, and this will fullscreen the all page.

So I think we should take a look at the project jquery.fullscreen. It has a fall back on IE7-IE10.

It seems that they polyfill by css.

初始化时未传入src属性报错

代码大概如下:

this.player = new Chimee({
    width: this.width,
    height: this.height,
    wrapper: this.$refs.player,
    isLive: this.isLive,
    autoplay: true,
    controls: true
});

此时只是想初始化播放器,后续通过load方法载入视频,但是目前会直接报video player is not already, must init player

debug了一下代码发现在播放器初始化的时候会自动去加载src内容,此时src为空,走入后面逻辑

Change `preset` to `kernels`

In current time, we use preset to install the other kernel like chimee-kernel-flv.Which is blur and confused.

So we decide to change it into kernels. Which it's easy to read.

While we will support install kernel later, this make kernel installing clearly.

width与height属性的设置问题

目前chimee内部对于width与height的设置并未直接作用于video标签或者warpper上,这样会导致一类问问题,比如如下场景

<template>
<div class="chimee-player" ref="player"></div>
</template>

<script>
import Chimee from 'chimee';
import flv from 'chimee-kernel-flv';
import hls from 'chimee-kernel-hls';

export default {
    props: {
        width: {
            type: Number,
            default: 800
        },
        height: {
            type: Number,
            default: 450
        }
    },
    data() {
        return {
            player: null
        };
    },
    mounted() {
        this.player = new Chimee({
            width: this.width,
            height: this.height,
            wrapper: this.$refs.player,
            src: 'http://flv-live.jia.360.cn/live_jia_public/_LC_RE_non_3605172938515097363411231238_CX.flv',
            controls: true,
            autoplay: true,
            kernels: {
                flv,
                hls
            }
        });
        this.player.on('play', () => console.log('play!!'));
    }
};
</script>

<style lang="stylus" scoped>
div
    width 100%
    height 100%
    color #ff9000
</style>
<style lang="stylus">
.chimee-player video
    width: 100%
    height: 100%
</style>

目前的width height设置无效的情况下,只能通过非scoped的style样式来解决,因为vue-loader中对于scoped css的处理是对template内或者render函数最后编译成的的virtual dom做遍历生成scoped attr,而在类似上面代码中的应用,因video是动态生成的,scoped css无法应用到video上,所以只能暂时性hack方式来保证样式准确性。

且开发者看文档中会觉得width/height在当前状况下指的就是播放器本身的大小,希望这块能够支持一下~~~ 谢谢~

移动端构建 ROADMAP

需求汇总

需求确定后在此更新 ROADMAP 用于同步信息。

  • 利用微信 jssdk 兼容移动端直播的场景。
  • 微信小程序内使用调研:
    微信小程序环境通过 videolive-player 组件提供了视频播放功能,基于 cover-view 可以实现UI自定义;配合微信开放的自定义组件方案,可以开发相应独立组件;官方说小程序中Video是基于Native实现的,通过文档没找到扩展解码能力的方法。

能否支持背景图片

现在背景只能用css填充,是否可以增加一个背景图片的参数? 这个是统一在接口上处理,还是交由用户自己处理?

一个页面同时开多个直播播放器,只有一个生效了

要做多窗口直播,但是发现对不同id的div元素初始化chimee实例,只有一个能播放,其他的就停下来了。在点播视频,我开了两个,两个都是正常播放。是不是目前不支持多开直播?或者是多开直播占用了同一个缓冲区,导致了冲突?

ROADMAP

  • $watch
    finished in 0.1.3
  • width and height of video should support percentage (support in 0.2.0
  • add isFullScreen on video to tell plugin the fullscreen state, or make fullscreen pass by event (support in 0.2.0)
  • support offsetHeight, offsetWidth etc (support in 0.2.0)
  • support error on video (support in 0.2.0)
  • support silent load (support in 0.2.0)
    Developer may want to support multi-clarity. If they change clarity by loading a new src. That is slow. So it may be a good idea to support silent load and change the video when loading is finished.
  • load new src including box change (support in 0.2.0)
    As in silent load we can change box and kernel, we can also support change box on load too
  • custom kernel (support in 0.2.0)
    user can choose the kernel. In that way, we can reduce our code size.
  • add some css guide on document and think about what should we do on css
  • throw plugin name
  • fix plugins and plugin error on document or support both
  • fix fullscreen on IE9-IE10 (fixed in 0.2.8)
  • add fullscreen event on chimee (fixed in 0.2.8)
  • fix load empty bug on non-autoload mode (fixed in 0.2.8)
  • silentload events
  • support static preset install (will be landed on 0.4.0)
  • add autoload tips on demo
    when people haven't pass src but mark with autoload, we should offer a tips
  • use babel-env to build
  • english document and guidance
  • environment test
    offer a method like isSupport to let user know whether the kernel is supported in this environment.
  • check preset and kernels on chimee layer
    mostly check with box setting, but this is basically job of kernel

----- discussion

  • weex
  • chimee with pwa
  • debug mode and code minify
  • 小程序
    support better debug experience and minify debug code

预加载方案 ROADMAP

预加载方案构思

  • 多个视频之间的预加载
    做法:增加一个隐藏 video 加载流,需要的时候直接切换即可。

  • cacheStorage 配合 PWA 完成
    做法,利用 cacheStorage 存储片段,拦截请求返回。注意判断 storage 的限制

  • localStorage 或 indexedDB 读取
    这个可能要修改一下各个 kernel 的设置,另外限制比较大。和光宇衡量。

移动端的相关事件暴露

  1. 目前 chimee 没有暴露, touch 类的相关类的移动端事件。

  2. 目前移动端, 手势比较多, 播放器,常用的三个手势,点击/拖动/滑动, 这几个手势封装在 chimee 比较好, 还是,插件自己去封装比较好???
    我个人比较赞成封装在插件内。原因是,大部分插件的手势其实都是点击操作,只有少部分, 像 controlbar 才会有这几种手势的应用。 后期手势的扩展也是, 插件自己扩展就好了, 不然, chimee 的代码也是越来越多。

Document problem

If you find document hard to read or you have some advice, you can tell me here.

Log 配置在flv里不生效

log: {
error: false,
info: false,
warn: false,
debug: false,
verbose: false,
}
配置了 log 但是在flv里 Log.verbose 等 依然会打印出来
Log 继承的是 chimee-helper-log

全屏api与container设置冲突的问题

0.50以后可以对player.container进行设置 ,
比如我设置player.container.width=640px
player.container.height=360px

当我点击全屏按钮后,浏览器进入全屏状态 container的区域还是640x360大小,没有铺满
chimee 是否应该自动接管这里,让container真正全屏,

全屏使用
方法 $fullscreen
全屏的对象,可选video、container和wrapper
默认:container

按照一般的理解既然传入了区域,那么这个区域大小就得跟全屏的大小一样才对

事件分发层绑定时存储的handler与解绑时错位

相关变量:videoEventHandlerList videoDomEventHandlerList,只有push没有pull,但解绑时索引每次都是从0开始。

所以多切几次流让 videoElement销毁创建多次 ,HandlerList就会一直push,导致最后销毁播放器实例时候解绑失败,会报告事件异常。

相关代码:

https://github.com/Chimeejs/chimee/blob/master/src/dispatcher/dom.js#L143

https://github.com/Chimeejs/chimee/blob/master/src/dispatcher/dom.js#L148

https://github.com/Chimeejs/chimee/blob/master/src/dispatcher/dom.js#L158

https://github.com/Chimeejs/chimee/blob/master/src/dispatcher/dom.js#L161

kernel 底层配置问题

目前,底层参数是在chimee的配置中传入进来的,目前hls、flv、mp4底层所用到的参数都是从这个配置中取的,mp4 只有点播,flv 有直播有点播,hls使用开源项目。
hls 参数有非常多,参见 hls api
flv目前需要这些参数
isLive: false, // 是否是直播
seekInKeyframe: true, // 总是seek 到关键帧
alwaysSeekKeyframe: true, // 总是seek 到关键帧
lazyLoadMaxDuration: 2 * 60, // 懒加载 最大播放长度
lazyLoadRecoverDuration: 30, // 懒加载还有多少长度 重启加载功能
lockInternalProperty: false, // 锁定原生的选项
webWorker: false, // 是否开启webworker
autoCleanupSourceBuffer: true, // 是否自动清除 sourcebuffer
autoCleanupMaxBackwardDuration: 30, // 清除sourcebuffer最大时间
autoCleanupMinBackwardDuration: 30, // 清除sourcebuffer最小时间
stashSize: 1024 * 384, // io缓存大小 直播下建议设置成 1024 * 128
seekType: 'range' // seek请求的方式 是range 还是 query
mp4暂时和flv 的差不多 因为都是我实现的,但是以后可能会有不同的差异,因为mp4没有直播。
目前底层需要改动一个参数,需要上层改动代码,而不是透传进来。
是否可以改成
kernels: { flv: { kernel: flv, config: confg } }
目前公用的参数比较少,欢迎讨论一下

关于isLive的参数配置

目前isLive的的选项除了在controller-plugin中看到使用外,地方并无看到使用,而且此处又与plugin中细粒度控制图标展示与否冲突,有一定的歧义性,希望对于此参数做进一步考虑

rtmp协议

现在是否支持rtmp协议的解析?想播放rtmp协议开头的视频文件,有例子吗?

使用此播放器播放存储在腾讯云的flv,播放不了,但是这个flv地址通过其他播放器是可以的

flv地址:http://1253804432.vod2.myqcloud.com/3712977fvodgzp1253804432/f3f31e5f9031868223411915443/f0.flv

vlc播放成功、腾讯tcplayer也能播放。
2017-11-06 4 21 17
使用chimee播放报错。

Failed to load http://1253804432.vod2.myqcloud.com/3712977fvodgzp1253804432/f3f31e5f9031868223411915443/f0.flv: Response for preflight has invalid HTTP status code 400

2017-11-06 4 22 37

麻烦团队大牛帮我看一下,是解码器的问题吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.