收藏
回答

使用wx.chooseMedia上传视频,选择视频文件时提示“不能分享短于1s的视频”,咋办?

wx.chooseMedia({

      count: 1,

      mediaType: ['video'],

      sourceType: ['album', 'camera'],

      maxDuration: 10,

      camera: 'back',

      success(res) {

        console.log('选择视频成功', res)

        // 增加结果检查,确保tempFiles数组存在且有元素

        if (!res.tempFiles || res.tempFiles.length === 0) {

          console.error('无效的返回数据结构:', res)

          wx.showToast({

            title: '视频数据格式错误',

            icon: 'none'

          })

          return

        }

       

        try {

          const tempFilePath = res.tempFiles[0].tempFilePath

          const size = res.tempFiles[0].size

          const duration = res.tempFiles[0].duration || 0

          const width = res.tempFiles[0].width || 0

          const height = res.tempFiles[0].height || 0

         

          // 检查视频大小,限制在10MB以内

          if (size > 10 * 1024 * 1024) {

            wx.showToast({

              title: '视频大小不能超过10MB',

              icon: 'none'

            })

            return

          }

         

          // 检查视频时长,允许0-2秒的视频

          if (duration < 0 || duration > 2) {

            wx.showToast({

              title: '视频时长必须在0-2秒之间',

              icon: 'none'

            })

            return

          }

         

          // 计算FPS(如果没有直接提供,则使用默认值30)

          const fps = 30

         

          that.setData({

            videoPath: tempFilePath,

            videoInfo: {

              duration: duration,

              size: size,

              width: width,

              height: height,

              fps: fps

            }

          })

        } catch (e) {

          console.error('处理视频数据时出错:', e)

          wx.showToast({

            title: '处理视频数据失败',

            icon: 'none'

          })

        }

      },


回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    2025-11-04

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2025-11-04
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    2025-11-02
    有用
登录 后发表内容