<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] 音樂播放帶旋轉 ## 要點 * 獲取背景音樂 ``` wx.getBackgroundAudioManager(); ``` * 點擊播放 ``` onMusic(){ if (this.data.isPlay){ this.setData({ isPlay:false }) audio.pause(); } else{ audio.title = this.properties.title; audio.src = this.properties.url; this.setData({ isPlay:true }) } } ``` * 監聽與頁面保持一致 * attached 函數 你不在method里 ``` //當組件觸發 attached 生命周期時,會依次觸發 my-behavior 中的 attached 生命周期函數和 my-component 中的 attached 生命周期函數 attached(){ //監聽音頻播放事件 audio.onPlay(()=>{ this.setData({ isPlay:true }) }) //監聽音頻暫停事件 audio.onPause(()=>{ this.setData({ isPlay:false }) }) //監聽音頻停止事件 audio.onStop(()=>{ this.setData({ isPlay:false }) }) //監聽音頻自然播放至結束的事件 audio.onEnded(()=>{ this.setData({ isPlay:false }) }) } ``` # 具體代碼 ## js ``` const audio = wx.getBackgroundAudioManager(); Component({ /** * 組件的屬性列表 */ properties: { title: String, url: String }, behaviors:[common], /** * 組件的初始數據 */ data: { isPlay:false }, /** * 組件的方法列表 */ methods: { onMusic(){ if (this.data.isPlay){ this.setData({ isPlay:false }) audio.pause(); } else{ audio.title = this.properties.title; audio.src = this.properties.url; this.setData({ isPlay:true }) } } }, //當組件觸發 attached 生命周期時,會依次觸發 my-behavior 中的 attached 生命周期函數和 my-component 中的 attached 生命周期函數 attached(){ //監聽音頻播放事件 audio.onPlay(()=>{ this.setData({ isPlay:true }) }) //監聽音頻暫停事件 audio.onPause(()=>{ this.setData({ isPlay:false }) }) //監聽音頻停止事件 audio.onStop(()=>{ this.setData({ isPlay:false }) }) //監聽音頻自然播放至結束的事件 audio.onEnded(()=>{ this.setData({ isPlay:false }) }) } }) ``` ## wxml ``` <view class='music' > <image src="/images/banner.png" class="banner {{isPlay?'rotate':''}}" ></image> <image src="{{isPlay?'/images/play.png':'/images/pause.png'}}" class='music-img' bind:tap="onMusic"></image> </view> ``` ## wxss ``` .music{ display: flex; flex-direction: column; justify-content: center; align-items: center; } .banner{ width: 200px; height: 200px; border-radius:100px; } .music-img{ width: 60px; height: 60px; position: absolute; top: 70px; z-index: 10; } .rotate{ animation: rotate 12s infinite; } @keyframes rotate{ from{ transform: rotate(0deg) } to{ transform: rotate(360deg) } } ```
                  <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>

                              哎呀哎呀视频在线观看