请问mp3url的参数格式是什么,我的url识别不出duration音频的长度
发布于 6 年前 作者 duanyong 7729 次浏览 来自 问答

wx.playBackgroundAudio(OBJECT)

能播放就是识别不出duration

得播完了再播有时候才有

3 回复

目前我写的一个,感觉还是有不少的问题,就是未播放的时候无法获取音频时长,只能默认为00:00,点击播放的时候才会获取时长。倒计时显示,在开发工具上暂停和播放还可以,但是用真机就不行了,卡顿相当严重,仅供参考。

页面

<view>

    <image src="/image/{{isPlay?‘stop’:‘play’}}.png" class=“audio_image” bindtap=“play”></image>

</view>

js控制

Page({

  data: { isPlay: false },

  onLoad: function (options) {

  },

  onReady: function (e) {

  },

  play: function () {

    var isPlay = this.data.isPlay;

    if (isPlay) {

      wx.pauseBackgroundAudio();

      this.setData({ isPlay: false });

    } else {

      wx.playBackgroundAudio({

        dataUrl: “”,

        title: “”,

        coverImgUrl: “”

      });

      this.setData({ isPlay: true });

    }

    countdown(this);

  }

})

function countdown(that) {

  wx.getBackgroundAudioPlayerState({

    success: function (res) {

      if (res.status == 1) {

        var time = setTimeout(function () {

          that.setData({ time: dateformat(res.duration - res.currentPosition) });

          countdown(that);

        }, 500);

      }

    },

    fail: function () {

      that.setData({ time: “00:00” });

      if (that.data.isPlay) {

        var time = setTimeout(function () {

          countdown(that);

        }, 1000);

      }

    }

  });

}

function dateformat(second) {

  var dateStr = “”;

  var min = Math.floor(second / 60);

  var sec = (second - min * 60);

  dateStr = min + “:” + (sec < 10 ? “0” + sec : sec);

  return dateStr;

}

有么办法用php解码录音文件吗?

那个貌似是我解码有问题,录音文件,通过

wx.uploadFile(OBJECT)上传到服务器 会在我的录音文件掺东西吗

回到顶部