收藏
回答

如何解决小程序开发视频保存到本地相册错误?

<video style='width:300rpx;height:300rpx;' id="myVideo" bind:longpress='saveVideo' src="{{video}}" enable-danmu danmu-btn controls></video>

Page({

 data: {

   video: ''

 },

saveVideoToAlbum: function () {

   var that = this;

   wx.saveVideoToPhotosAlbum({

     filePath: that.data.video,

     success(res){

       wx.showToast({

         title: '视频下载成功',

         icon: 'success',

         duration: 2000

       })

     },

     fail(res){

       console.log(res)

       console.log(that.data.video)

       wx.showToast({

         title: '下载失败,请稍后重试',

         icon: 'success',

         duration: 2000

       })

     }

   })

 },

 saveVideo: function(){

   var that = this;

   console.log(that.data.video)

   wx.getSetting({

     success(res) {

       // 进行授权检测,未授权则进行弹层授权

       if (!res.authSetting['scope.writePhotosAlbum']) {

         wx.authorize({

           scope: 'scope.writePhotosAlbum',

           success() {

             that.saveVideoToAlbum()

           },

           // 拒绝授权时,则进入手机设置页面,可进行授权设置

           fail() {

             wx.openSetting({

               success: function (data) {

                 console.log("openSetting success");

               },

               fail: function (data) {

                 wx.showToast({

                   title:'正在授权,请稍等...',

                   icon:'loading',

                   duration:2000

                 })

                 console.log("openSetting fail");

               }

             });

           }

         })

       } else {

         // 已授权则直接进行保存图片

         that.saveVideoToAlbum()

       }

     },

     fail(res) {

       console.log(res);

     }

   })

 }

})

然后长按视频下载,他老是弹出‘下载失败,请稍后重试’,这个主要问题是出在哪呢,

补充下打印结果是



最后一次编辑于  2019-09-21
回答关注问题邀请回答
收藏

1 个回答

  • fend
    fend
    2019-09-21


    测试可行

    2019-09-21
    有用
    回复 1
    • fend
      fend
      2019-09-21

      看看微信后台有没有配置视频地址所在的域名

      2019-09-21
      回复
登录 后发表内容
问题标签