<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## 要點(小程序升級了) ### 點擊事件 ``` onMusic() { if (this.data.isPlay) { audio.pause(); this.setData({ isPlay: false }) } else { // audio.title = this.properties.title; audio.src = this.properties.musicUrl; this.setData({ isPlay: true }) } } ``` ### 恢復音樂函數 ``` //當重新進入頁面 恢復音樂 播放或暫停 _recoveryMusic() { //如果監聽到的src 與 properties的musicUrl相同時 讓音樂播放 if (audio.src == this.properties.musicUrl) { this.setData({ isPlay: true }) } //如果監聽到的 paused(audio的屬性) 為true時 設置isPlay為false if (audio.paused) { this.setData({ isPlay: false }) } }, ``` ### 監聽音樂函數 讓監聽與播放保持一致 ``` //監聽音樂 _monitorMusic() { //監聽音頻播放事件 audio.onPlay(() => { this.setData({ isPlay: true }) }) //監聽音頻暫停事件 audio.onPause(() => { this.setData({ isPlay: false }) }) //監聽音頻停止事件 audio.onStop(() => { this.setData({ isPlay: false }) }) //監聽音頻自然播放至結束的事件 audio.onEnded(() => { this.setData({ isPlay: false }) }) } ``` ### 調用函數 ``` //當組件觸發 attached 生命周期時,會依次觸發 my-behavior 中的 attached 生命周期函數和 my-component 中的 attached 生命周期函數 attached() { this._recoveryMusic(); this._monitorMusic(); } ``` # 完整js ``` // components/classic/music/index.js const audio = wx.getBackgroundAudioManager() Component({ /** * 組件的屬性列表 */ properties: { content: { type: String }, image: { type: String }, musicUrl: { type: String } }, /** * 組件的初始數據 */ data: { isPlay: false }, /** * 組件的方法列表 */ methods: { onMusic() { if (this.data.isPlay) { audio.pause(); this.setData({ isPlay: false }) } else { // audio.title = this.properties.title; audio.src = this.properties.musicUrl; this.setData({ isPlay: true }) } }, //當重新進入頁面 恢復音樂 播放或暫停 _recoveryMusic() { //如果監聽到的src 與 properties的musicUrl相同時 讓音樂播放 if (audio.src == this.properties.musicUrl) { this.setData({ isPlay: true }) } //如果監聽到的 paused(audio的屬性) 為true時 設置isPlay為false if (audio.paused) { this.setData({ isPlay: false }) } }, //監聽音樂 _monitorMusic() { //監聽音頻播放事件 audio.onPlay(() => { this.setData({ isPlay: true }) }) //監聽音頻暫停事件 audio.onPause(() => { this.setData({ isPlay: false }) }) //監聽音頻停止事件 audio.onStop(() => { this.setData({ isPlay: false }) }) //監聽音頻自然播放至結束的事件 audio.onEnded(() => { this.setData({ isPlay: false }) }) } }, //當組件觸發 attached 生命周期時,會依次觸發 my-behavior 中的 attached 生命周期函數和 my-component 中的 attached 生命周期函數 attached() { this._recoveryMusic(); this._monitorMusic(); } }) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看