1.7 微信小程序-视频播放器-发送弹幕

本文介绍了如何在微信小程序中创建一个视频播放器,并实现了弹幕发送功能。内容包括视频播放器页面制作,选择弹幕颜色的交互,以及Video插件的使用。详细讲解了video-detail和select-color两个页面的wxml、wxss和js代码,并展示了最终的页面实现效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、视频播放器

video-detail 视频播放器
select-color 发送弹幕

1. 页面制作
小脆筒

2. 选择弹幕颜色
小脆筒
2、 Video插件的使用

在这里插入图片描述

3. 相关代码

  • app.json
//app.json
{
   
   
  "pages":[
    "pages/video-detail/video-detail",
    "pages/select-color/select-color",
    "pages/index/index",
    "pages/logs/logs"
  ],
  "window":{
   
   
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "视频播放器",
    "navigationBarTextStyle":"black"
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json"
}

  • app.wxss
/**app.wxss**/
.container {
   
   
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 200rpx 0;
  box-sizing: border-box;
} 

二、video-detail 视频播放器相关页面代码

  • video-detail.wxml
<!--pages/video-detail/video-detail.wxml-->
<view class="mainContent">
    <view class="mainList">
        <view class="playerInfo" data-src="{
   
   {videoDetail.videoUrl}}" wx:if="{
   
   {current_id && current_id == videoDetail.id}}">
            <view class="video">
                <video class="videoContent" id="videoId" show-center-play-btn="true" autoplay="true"
                    danmu-list="{
   
   {danmuList}}" danmu-btn enable-danmu
                 src="{
   
   {videoDetail.videoUrl}}" object-fit="fill" bindfullscreenchange="fullscreenchange"></video>
            </view>
        </view>
        <view class="playerInfo" data-src="{
   
   {videoDetail.videoUrl}}" wx:if="{
   
   {current_id =='' || current_id != videoDetail.id}}">
            <view class="video">
                <image class="playImg" src="/images/play.png" mode="aspectFill" bindtap="videoPlay" id="{
   
   {videoDetail.id}}" data-index="videoId"/>
                <image class="videoContent" src="{
   
   {videoDetail.poster}}" mode="aspectFill" bindtap="videoPlay" id="{
   
   {videoDetail.id}}" data-index="videoId"/>
            </view>
        </view>
    </view>
    <!--弹幕-->
    <view class="danmu">
        <view class="danmu-input">
            <input class="weui-input" type="text" placeholder="请输入弹幕" bindblur="bindInputblur"/>
        </view>
        <view class="danmu-btn">
            <button type="primary" bindtap = "bindSendDanmu">发送弹幕</button>
        </view>
        <view class="danmu-color">
            <view class="danmu-color-switch">
                <view class="weui-cell-bd">随机颜色</view>
                <view class="weui-cell-ft">
                    <switch checked="true" type="switch" bindchange="switchChange"></switch>
                </view>
            </view>
            <view class="danmu-color-select" bindtap = "selectColor">
                <view class="weui-cell-bd">选择颜色</view>
                <view class="weui-cell-ft">
                    <view class="selectColor" style="background-color: {
   
   {numberColor}};"></view>
                </view>
            </view>
        </view>
    </view>
</view>


  • video-detail.wxss

.mainContent{
   
   
  background: #ffffff;
  overflow: auto;
}
.mainList{
   
   
  width:100%;
  background: #ffffff
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小脆筒style

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值