zoukankan      html  css  js  c++  java
  • vue播放视频

    <template>
    <view>
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt" v-if="showVideo">
    <view>
    <video id="myVideo" src="http://cctvalih5ca.v.myalicdn.com/live/cctv1_2/index.m3u8"
    @error="videoErrorCallback" :danmu-list="danmuList" enable-danmu danmu-btn controls poster="https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/poster.png"></video>
    </view>
    <!-- #ifndef MP-ALIPAY || MP-TOUTIAO -->
    <view class="uni-list uni-common-mt">
    <view class="uni-list-cell">
    <view>
    <view class="uni-label">弹幕内容</view>
    </view>
    <view class="uni-list-cell-db">
    <input v-model="danmuValue" class="uni-input" type="text" placeholder="在此处输入弹幕内容" />
    </view>
    </view>
    </view>
    <view class="uni-btn-v">
    <button @click="sendDanmu" class="page-body-button">发送弹幕</button>
    </view>
    <!-- #endif -->
    </view>
    </view>
    </view>
    </template>
    <script>
    export default {
    data() {
    return {
    title: 'video',
    src: '',
    danmuList: [{
    text: '第 1s 出现的弹幕',
    color: '#ff0000',
    time: 1
    },
    {
    text: '第 3s 出现的弹幕',
    color: '#ff00ff',
    time: 3
    }
    ],
    danmuValue: '',
    showVideo: false
    }
    },
    onReady: function(res) {
    // #ifndef MP-ALIPAY || MP-TOUTIAO
    this.videoContext = uni.createVideoContext('myVideo')
    // #endif
    // #ifdef APP-PLUS || MP-BAIDU
    setTimeout(()=>{
    this.showVideo = true
    },350)
    // #endif
    // #ifndef APP-PLUS || MP-BAIDU
    this.showVideo = true
    // #endif
    },
    methods: {
    sendDanmu: function() {
    this.videoContext.sendDanmu({
    text: this.danmuValue,
    color: this.getRandomColor()
    });
    this.danmuValue = '';
    },
    videoErrorCallback: function(e) {
    uni.showModal({
    content: e.target.errMsg,
    showCancel: false
    })
    },
    getRandomColor: function() {
    const rgb = []
    for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length == 1 ? '0' + color : color
    rgb.push(color)
    }
    return '#' + rgb.join('')
    }
    }
    }
    </script>

    <style>
    video {
    690rpx;
    }
    </style>

  • 相关阅读:
    电子招投标应用系统连载(一)-开标系统
    js实现一个简单钟表动画(javascript+html5 canvas)
    ,net core mvc 文件上传
    echarts显示X轴最后一个lable
    C# 解压gzip文件(.tgz)
    【转】C#计算两坐标点距离
    用file标签实现多图文件上传预览
    c#数据批量插入
    Asp.net 中ViewState,cookie,session,application,cache的比较
    ASP.NET MVC从请求到响应发生了什么
  • 原文地址:https://www.cnblogs.com/xuandi/p/14757445.html
Copyright © 2011-2022 走看看