Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

width与height属性的设置问题 #12

Closed
skyline0705 opened this issue Nov 8, 2017 · 6 comments
Closed

width与height属性的设置问题 #12

skyline0705 opened this issue Nov 8, 2017 · 6 comments

Comments

@skyline0705
Copy link
Contributor

skyline0705 commented Nov 8, 2017

目前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在当前状况下指的就是播放器本身的大小,希望这块能够支持一下~~~ 谢谢~

@toxic-johann
Copy link
Member

关于宽高的设置。

相关历史理解

早期的设计思想,wrapper 为外层容器,container 为内层容器,video 为原生容器。三者之间不一定等价。例如 wrapper 中可以嵌入播放列表,container 包括控件等思想。

在插件层其实可以直接访问到相关 wrapper, video, container 节点。对于插件开发者也有$css 可以调整 css 的相关样式。

不过以上方面对于 chimee 层的使用者均不提供。这里大家可以讨论下开放出去有没有利弊。

关于 width 和 height 的意义

早期的设置是将所有 video 的 attribute 开放出来,所以这个 width 和 height 确实只是针对 video,在理解上的确有歧义。我们曾经讨论过关于 css 的设置。当时得出的结果是希望用户去理解 container 和 wrapper 这种设计。

但是我们也可以看到,这给用户带来各种开箱后用不了的问题。此时,我们可以思考是否有必要改进这个 api。

思考解决方案有,width 和 height 智能化。

当用户只传入一个值时,我们考虑为宏观值,给 container 设置。

当用户传入一个 对象,形如

{
    videoWidth: 10,
    containerWidth: 10,
    wrapperWidth: 10,
}

我们才分别设置。

不过这个思考有不周到之处。

设置 width 和 height 其余的坑点

还有一个十分重要的场景是关于全屏。如果用户设置后会有什么问题,会不会阻碍用户顺利全屏呢。大家可以探讨下。

@huzunjie @songguangyu @332065255 @yandeqiang

@skyline0705
Copy link
Contributor Author

我觉得这里直接通过单一对象的方式其实不太利于后期扩展。
如果按照目前的设计思想, wrapper, video, container三者可以分开设置相关的config,比如:

const config = {
    video: {
        width: 800,
        height: 450
    },
    wrapper: {
        width: 900,
        height: 450
    },
    container: {
        width: 800,
        height: 450
    }
}

这样拆分起来比起

{
    videoWidth: 10,
    containerWidth: 10,
    wrapperWidth: 10
}

这种方式个人觉得会清晰一些,并且可以删除掉现有的width与height设置,只需要对使用者普及一下wrapper, video, container的概念即可

@toxic-johann
Copy link
Member

hmm。但现阶段 chimee 绝大部分的设置确实只存在在 video 上。而且如果分拆等于多加了一层。不过的确是可以提供 container、video 和 wrapper 作为子对象管理。这里面的设置相当于 css 或者其余我们日常用的设置。

形如:

{
       // video 上的 attribute
       width: 100,
       height: 90,
       // video 上的 css
       video: {
            width: '100px'
            height: '90px'
       },
       wrapper: {
            width: 900,
            height: 450
        },
       container: {
            width: 800,
            height: 450
        },
}

不过这确实增加了很多学习成本。但是从实现上来说这样是行之有效的。而且我们官方也可以相当于通过默认配置提供较好的 css 默认设置。

@songguangyu
Copy link
Member

wrapper 其实可以用户自己来设置。
chimee 需要关注的是container 和 video。 是否应该 container 和 video 默认是100% 也就是和wrapper保持一致,然后提供一个对象集合来专门设置css样式。就像楼上写的那样。

@toxic-johann
Copy link
Member

Hmmm.如果大家觉得 js hardcode container 和 wrapper 的 css 是可以接受的话。个人觉得还是可以尝试一下这种操作。

toxic-johann added a commit that referenced this issue Nov 12, 2017
1. add containerConfig
2. fix default width and default height do not work bug
toxic-johann added a commit that referenced this issue Nov 12, 2017
@toxic-johann toxic-johann added fixed and removed todo labels Nov 12, 2017
@toxic-johann
Copy link
Member

已在 0.5.0 修复

toxic-johann added a commit that referenced this issue May 31, 2019
…nerConfig 2. fix default width and default height do not work bug
toxic-johann added a commit that referenced this issue May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants