iOS 音频播放要加载6-7秒,安卓没问题
发布于 5 年前 作者 leigu 7998 次浏览 来自 问答

使用的是阿里云oss存储的音频。格式为mp3。

点击开始播放需要加载好几秒,切换别的语音,再点之前播放过得,也要重新加载好久,就算是几秒的语音也要加载好久

以下为语音:

<!--  语音  -->
            <view class="row-module-audio" wx:if="{{item.SpeechType == 1}}">
                <view class="audio-item detail-direction {{audioplaying == index && !audioplay ? 'audio-item-loading' : ''}}" data-src="{{item.ModuleContent.Url}}" data-index="{{index}}" bindtap='audioPlay' style="width:{{item.ModuleContent.Seconds != 0 && item.ModuleContent.Seconds != null ? item.ModuleContent.width : ''}};">         
                    <view class="audio-state {{audioplaying == index && audioplay ? 'audio-item-playing' : ''}}"></view>
                    <text>{{item.ModuleContent.Seconds != 0 && item.ModuleContent.Seconds != null ? item.ModuleContent.size : '00:00/00:00'}}</text>
                </view>
            </view>

以下为播放JS:

audioPlay: function(e) {
        var that = this
        var src = e.currentTarget.dataset.src
        var index = e.currentTarget.dataset.index
        var audioplaying = this.data.audioplaying
        var videoPlaying = this.data.videoPlaying
        //如果有正在播放的音频且不是当前点击的音频,暂停播放该音频。是当前点击的,则停止播放音频
        if (audioplaying != null){
            if (audioplaying != index) {
                clearInterval(that.playTimer)
                that.setItemData(audioplaying)
                audioplaying = index
                audio.src = src
                audio.play()
            } else {
                audioplaying = null
                audio.stop()
                clearInterval(that.playTimer)
                that.setItemData(index)
            }
        } else {
            audioplaying = index
            audio.src = src
            audio.play()
        }
        //如果有正在播放额视频,暂停播放该视频
        if (videoPlaying != null){
            var videoContextPrev = wx.createVideoContext('video_' + videoPlaying)
            videoContextPrev.pause()
        }
         
        this.setData({
            audioplaying: audioplaying,
            audioplay: false,
            videoPlaying: null
        })
    }

求助。问题直接和体验挂钩。

回到顶部