uni-app实现微信小程序长按拍视频功能

 更新时间:2022年08月28日 09:06:46   作者:红豆O(∩_∩)O  
这篇文章主要为大家详细介绍了uni-app实现微信小程序长按拍视频功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了uni-app实现微信小程序长按拍视频功能的具体代码,供大家参考,具体内容如下

html

<!-- 上传视频 -->
     <view class="Voice_input">
                <text class="Voice_title">上传视频:</text>
                <view class="" >
                    <view class="video_image">
                        <view class="video_box" v-for="(item,index) in videoSrc" :key='index'>
                            <video v-show="videoSrc" class="showvideo" :src="item"></video>
                        </view>
                        <image class="videoshow" v-show="showvideoimga"  src="../../static/images/yinyue.png" @tap="showvideo"></image>
                    </view>
                    <view>
                        <progress :percent="deflautWidth" v-show="showProgress" color="pink" stroke-width="15" class="progressStyle" />
                        <!-- <progress percent="deflautWidth" hidden="showProgress" color="pink"   stroke-width="15"  class="progressStyle" /> -->
                        <camera   v-show="hidden" flash="off" style="width: 100%; height: 100%;position:fixed;top:0;z-index:1111;left:0;"></camera>
                        <view class="btn-area"  >
                            <view class="">
                         <text  class="videBtn" @touchstart="handleTouchStart" @touchend="handleTouchEnd" v-show="hidden" @longpress="handleLongPress" >按住拍</text>
                            </view>
                        </view>
                    </view>
        </view>                
</view>

css样式

/* 上传视频 */
    .video_image{
        width: 700rpx;
        /* height: 99px; */
        margin-bottom: 15px;
        display: flex;
        flex-wrap: wrap;
        margin-top: 20rpx;
        
    }
    .video_box{
        margin-right: 20rpx;
        margin-top: 20rpx;
    }
    .video_image image{
        width: 200rpx;
        height: 200rpx;
        margin-top: 20rpx;
        margin-left: 10rpx;
    }
    .Voice_box{
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        margin-top: 15px;
        padding-bottom: 15px;
    }
    .videoshow{
      border: 1rpx solid #cccccc;
      width: 200rpx;
      height: 200rpx;
      /* margin:8px 10px; */
      /* position: relative; */
    }
    .videoConten{
      display: flex;
      align-items: center;
    }
    .showvideo{
      width: 200rpx;
      height: 200rpx;
    }
    .videBtn{
      position: fixed;
      bottom: 20rpx;
      left: 50%;
      transform:translateX(-50%);
      width: 200rpx;
      height: 200rpx;
      border-radius:50%;
      font-size: 35rpx;
      color:green ;
      text-align: center;
      line-height: 190rpx;
      border: 7rpx solid green;
      background:rgba(0,0,0,0);
      z-index: 11111;
      padding: 0;
      margin: 0;
    }
    .progressStyle{
      position: fixed;
      top: 0rpx;
      left: 0rpx;
      z-index: 111111;
      width: 100%;
    }

js部分

//在script标签最前面声明拍摄视频需要的api
    const recorderManager = uni.getRecorderManager();
    const innerAudioContext = uni.createInnerAudioContext('myAudio');
    innerAudioContext.autoplay = true;
    //录制视频start
            startShootVideo() {
                let index = 0;
                let that = this
                this.timer=setInterval(() => { //注意箭头函数!!
                    if(that.deflautWidth !=100){
                        index += 1;
                        that.deflautWidth = index
                    }
                    if (that.deflautWidth == 100) {
                        clearInterval(this.timer);
                    }
                }, 100);
                console.log("========= 调用开始录像 ===========")
                this.cameraContext = uni.createCameraContext();
                this.cameraContext.startRecord({
                    success: res => {
                        console.log("录像成功")
                        console.log(res)
                    }
                });
            },
            stopShootVideo() {
                //   console.log("========= 调用结束录像 ===========")
                this.cameraContext = uni.createCameraContext();
                this.cameraContext.stopRecord({
                    success: res => {
                        console.log('结束videoSrc')
                        
                        
                        this.videoSrc.push(res.tempVideoPath)
                        console.log(this.videoSrc)
                        this.hidden = false
                        this.showvideoimage = true
                    }
                });
            },
            // //touch start 手指触摸开始
            handleTouchStart(e){    
                this.starttime  =  e.timeStamp;    
                console.log(" startTime = "  +  e.timeStamp);  
                console.log(" 手指触摸开始 " ,  e);  
                console.log(" this " , this);  
            },
            //touch end 手指触摸结束
            handleTouchEnd(e){    
                clearInterval(this.timer);
                this.endtime  =  e.timeStamp;    
                this.stopShootVideo();
                // console.log(" endTime = "  +  e.timeStamp);  
                console.log(" 手指触摸结束 ", e);
                //判断是点击还是长按 点击不做任何事件,长按 触发结束录像
                if (this.endtime - this.starttime > 350) {
                    //长按操作 调用结束录像方法
                    this.stopShootVideo();
                }
                this.showProgress = false
                this.hidden = true
                this.showvideoimage = true
            },
            // /**
            //  * 长按按钮 - 录像
            //  */
            handleLongPress(e){
              console.log("endTime - startTime = "  +  (this.endtime  -  this.starttime));
              console.log("长按");
              // 长按方法触发,调用开始录像方法
              this.startShootVideo();
            },
            showvideo(){
              this.hidden = true
              this.showProgress = true
              // this.showvideoimga = true
            
            },
            //录制视频end

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • JS中showModalDialog关闭子窗口刷新主窗口用法详解

    JS中showModalDialog关闭子窗口刷新主窗口用法详解

    这篇文章主要介绍了JS中showModalDialog关闭子窗口刷新主窗口用法,结合具体实例形式较为详细的分析了showModalDialog常见用法与相关使用技巧,需要的朋友可以参考下
    2017-03-03
  • JS实现的驼峰式和连字符式转换功能分析

    JS实现的驼峰式和连字符式转换功能分析

    这篇文章主要介绍了JS实现的驼峰式和连字符式转换功能,结合实例形式分析了JS实现字符串的驼峰式与连接符式转换的实现技巧,涉及js字符串遍历、转换及正则表达式相关操作方法,需要的朋友可以参考下
    2016-12-12
  • 基于mouseout和mouseover等类似事件的冒泡问题解决方法

    基于mouseout和mouseover等类似事件的冒泡问题解决方法

    这篇文章主要介绍了关于mouseout和mouseover等类似事件的冒泡问题解决方法。需要的朋友可以过来参考下,希望对大家有所帮助
    2013-11-11
  • JavaScript WeakMap的具体使用

    JavaScript WeakMap的具体使用

    本文主要介绍了JavaScript WeakMap的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-02-02
  • javascript设计模式 接口介绍

    javascript设计模式 接口介绍

    最近在看javascript设计模式的书籍《pro javascript design pattrens》,觉得很不错,可以提高自己对js oo的理解,也可能帮助自己更好的理解别人写的js library,提高自己js的水平
    2012-07-07
  • js模拟hashtable的简单实例

    js模拟hashtable的简单实例

    本篇文章主要是对js模拟hashtable的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助
    2014-03-03
  • JavaScript设计模式中的观察者模式

    JavaScript设计模式中的观察者模式

    这篇文章主要介绍了JavaScript设计模式中的观察者模式,观察者设计模式适用于监听一对多的操作,例如监听对象属性的修改等等,观察者模式能够降低代码耦合度,提升可扩展性
    2022-06-06
  • BootStrap组件之进度条的基本用法

    BootStrap组件之进度条的基本用法

    bootstrap组件在前端开发中经常会用到,今天小编通过本文给大家分享bootstrap组件之进度条的基本用法,需要的朋友参考下吧
    2017-01-01
  • js实现随机抽选效果、随机抽选红色球效果

    js实现随机抽选效果、随机抽选红色球效果

    本文主要分享了js实现随机抽选效果、随机抽选红色球效果的示例代码。具有一定的参考价值,下面跟着小编一起来看下吧
    2017-01-01
  • 小程序开发实现access_token统一管理

    小程序开发实现access_token统一管理

    本文主要介绍了小程序开发实现access_token统一管理,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧
    2021-07-07

最新评论