国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序播放器的一些簡單功能實(shí)現(xiàn)

這篇具有很好參考價(jià)值的文章主要介紹了微信小程序播放器的一些簡單功能實(shí)現(xiàn)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

微信小程序播放器的一些簡單功能實(shí)現(xiàn)

準(zhǔn)備工作

一、構(gòu)建npm(后面用到moment的格式化時(shí)間)

微信小程序音樂播放器下一首的代碼,javascript,前端,npm

二、系統(tǒng)后臺(tái)監(jiān)測程序播放器配置(系統(tǒng)后臺(tái)要知道該播放器是否在播放歌曲,并有一些簡單的業(yè)務(wù)邏輯)

在app.json中添加以下代碼----和tarbar同級(jí)

"requireBackgroundModes": [
    "audio"
  ]

三、由于后面用到后臺(tái)需要監(jiān)測是哪首歌,需要有id和播放狀態(tài)

在app.js中添加如下代碼-----和onLaunch同級(jí)

GroupData:{
    MusicId:'',
    MusicPlay:false
  },

開始工作

涉及的功能介紹

1.單曲循環(huán)功能

2.上一首

3.下一首

4.播放

5.列表展示

6.進(jìn)度條實(shí)時(shí)

微信小程序音樂播放器下一首的代碼,javascript,前端,npm

由于本人比較懶,逐個(gè)功能介紹較復(fù)雜,直接附送源碼,如看代碼不明白,可直接聯(lián)系本人

js部分

import moment from 'moment'

const appInstance = getApp()
Page({

  /**
   * 頁面的初始數(shù)據(jù)
   */

  data: {
    isXunhuan:false,//是否開啟循環(huán)
    isPlay:false, //是否正在播放
    isShow:false,  //是否展示列表
    currentTimeFomat:'0:00', //當(dāng)前的時(shí)間---格式化后
    currentTime:'0', //當(dāng)前時(shí)間
    durationTime:'', //總時(shí)間
    currentWidth:0 , //進(jìn)度條寬度

    currentId:'001',  //當(dāng)前播放歌曲id
    currentUrl:'http://music.163.com/song/media/outer/url?id=317151.mp3',  //當(dāng)前播放歌曲地址
    currentTitle:'第一首',  //當(dāng)前播放歌曲名稱
    musicList:[{            //播放列表
      id:"001",
      url:'http://music.163.com/song/media/outer/url?id=317151.mp3',
      title:'第一首'
    },{
      id:"002",
      url:'http://downsc.chinaz.net/Files/DownLoad/sound1/201906/11582.mp3',
      title:'第二首'
    },{
      id:"003",
      url:'http://music.163.com/song/media/outer/url?id=298317.mp3',
      title:'第三首'
    }]
  },
  //點(diǎn)擊列表按鈕---展示列表頁
  showList(){
    this.setData({
      isShow:true
    })
  },
  //點(diǎn)擊別處--關(guān)閉列表頁
  colseList(){
    if(this.data.isShow){
      this.setData({
        isShow:false
      })
    }
  },
  //點(diǎn)擊列表里面的歌獲得當(dāng)前的歌曲
  musicListChange(e){
    this.setData({
      currentId:e.currentTarget.dataset.id,
      currentUrl:e.currentTarget.dataset.url,
      currentTitle:e.currentTarget.dataset.title,
    })
    this.musicControl(true)
  },
  //點(diǎn)擊播放按鈕
  bofang(){
    let isPlay = !this.data.isPlay  //修改播放狀態(tài)
    this.musicControl(isPlay)  //傳遞的是已經(jīng)修改了狀態(tài)
  },
  //播放函數(shù)
  musicControl(isPlay){
    console.log(isPlay)
    if(isPlay){
      this.BackgroundAudioManager.src=this.data.currentUrl,
      this.BackgroundAudioManager.title=this.data.currentTitle
    }else{
      this.BackgroundAudioManager.pause()
    }
  },
  xunhuan(){
    console.log("已經(jīng)開啟循環(huán)播放")
    this.setData({
      isXunhuan:true
    })
  },
  xiayishou(){
    const {musicList}=this.data
    let url=''
    let title=''
    let id=''
    for(let i=0;i<musicList.length;i++){
      if(this.data.currentId==musicList[i].id){
        url=musicList[i+1].url
        id=musicList[i+1].id
        title=musicList[i+1].title
     
      }
    }
    console.log(url,id,title)
    this.setData({
      currentTitle:title,
      currentUrl:url,
      currentId :id
    })
    this.musicControl(true)
   
  },
  xunhuan2(){
    const {musicList}=this.data
    let url=''
    let title=''
    let id=''
    for(let i=musicList.length-1;i>=0;i--){
      if(musicList[i].id==this.data.currentId){
        console.log(musicList[i].id)
        url=musicList[i].url
        id=musicList[i].id
        title=musicList[i].title
      }
    }
    this.setData({
      currentUrl:url,
      currentId:id,
      currentTitle:title
    })
    this.musicControl(true)

  },
  shangyishou(){
    const {musicList}=this.data
    let url=''
    let title=''
    let id=''
    for(let i=musicList.length-1;i>=0;i--){
      if(musicList[i].id==this.data.currentId){
        console.log(musicList[i].id)
        url=musicList[i-1].url
        id=musicList[i-1].id
        title=musicList[i-1].title
      }
    }
    this.setData({
      currentUrl:url,
      currentId:id,
      currentTitle:title
    })
    this.musicControl(true)

  },
  /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad(options) {
    this.BackgroundAudioManager =wx.getBackgroundAudioManager()
    
    // this.BackgroundAudioManager.src=this.data.currentUrl,
    // this.BackgroundAudioManager.title=this.data.currentTitle
    // this.BackgroundAudioManager.play()
    const MusicId=this.data.currentId
    console.log(appInstance.GroupData)
    //判斷當(dāng)前頁面音樂是否在播放
    if (appInstance.GroupData.MusicPlay && appInstance.GroupData.MusicId === MusicId) {
      //修改當(dāng)前音樂播放狀態(tài)為true
      this.setData({
        isPlay: true
      })
    }
    this.BackgroundAudioManager.onPlay(() => {
      this.setData({
        isPlay: true
      })
      appInstance.GroupData.MusicPlay = true
      appInstance.GroupData.MusicId = MusicId
    })
    this.BackgroundAudioManager.onPause(() => {
      this.setData({
        isPlay: false
      })
      appInstance.GroupData.MusicPlay = false
      //由于上面必定是先播放后停止所以省略 appIstance.GroupData.MusicPlay=false
    })
    this.BackgroundAudioManager.onStop(() => {
      this.setData({
        isPlay: false
      })
      appInstance.GroupData.MusicPlay = false
    })
    this.BackgroundAudioManager.onTimeUpdate(()=>{
      let currentTimeFomat=moment(this.BackgroundAudioManager.currentTime*1000).format('mm:ss')
      //  console.log(this.BackgroundAudioManager.currentTime)
      //  console.log(this.BackgroundAudioManager.duration)

      let durationTime=Math.floor(this.BackgroundAudioManager.duration)
      let currentWidth=this.BackgroundAudioManager.currentTime/this.BackgroundAudioManager.duration*450

     if(Math.floor(this.BackgroundAudioManager.duration)==Math.ceil(this.BackgroundAudioManager.currentTime)){
       if(this.data.isXunhuan==false){
        console.log("下一首了")
        this.xiayishou()
       }else{
         console.log("因?yàn)殚_啟了循環(huán)")
        this.xunhuan2()
       }
      
      }
      this.setData({
        currentTimeFomat,
        currentTime:Math.ceil(this.BackgroundAudioManager.currentTime),
        currentWidth,
        durationTime
      })
    });
    this.BackgroundAudioManager.onEnded(()=>{
      //進(jìn)度條置為0
      this.setData({
        currentWidth:0,
        currentTime:'0'
      })
    });
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面顯示
   */
  onShow() {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面隱藏
   */
  onHide() {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面卸載
   */
  onUnload() {

  },

  /**
   * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
   */
  onPullDownRefresh() {

  },

  /**
   * 頁面上拉觸底事件的處理函數(shù)
   */
  onReachBottom() {

  },

  /**
   * 用戶點(diǎn)擊右上角分享
   */
  onShareAppMessage() {

  }
})

html部分

<view class="container" >
  <text class="musicName" bindtap="colseList">{{currentTitle}}</text>
  <view class="circle">
    <image src="../../image/disc.png" alt="" class="disc"></image>
    <image src="../../image/needle.png"
    class="needle"></image>  
    <image src="../../image/nvsheng.jpg"
    class="nvsheng"></image>
  </view>
  <view class="progressbar">
    <text>0:00</text>
    <view class="barprogress">
      <view class="barprogress-timely" style="width:{{currentWidth+'rpx'}}"> 
        <view class="barcircle">
        </view>
      </view>
    </view>
    <text>{{currentTimeFomat}}</text>
  </view>

  <view class="controls">
   <view class="musicControls">
    <text class="iconfont icon-xunhuanbofang" bindtap="xunhuan"></text>
    <text class="iconfont icon-shangyishou" bindtap="shangyishou"></text>
    <text class="iconfont {{isPlay?'icon-zanting':'icon-bofang'}}" bindtap="bofang"></text>
    <text class="iconfont icon-xiayishou" bindtap="xiayishou"></text>
    <text class="iconfont icon-liebiao" bindtap="showList" hover-stop-propagation="true"></text>
   
  </view>
  <view class="songList" wx:if="{{isShow}}">
      <view class="songItem" wx:for="{{musicList}}" data-url="{{item.url}}" data-id="{{item.id}}" data-title="{{item.title}}" bindtap="musicListChange">{{item.id}}--{{item.title}}</view>
    </view>
   </view> 
</view>

css部分

.container{
  padding:20rpx;
  background-color: rgba(0,0,0,0.5);
  text-align: center;
  height:100%;
}
.musicName{
  color: white;
}
.circle{
  
  position: relative;
  margin-top:40rpx;
 
}
.disc{
  position: relative;
  z-index:1;
  height:598rpx;
  width:598rpx;
}
.needle{
  position:absolute;
  left:350rpx;
  top:-20rpx;
  height:200rpx;
  width:200rpx;
  z-index:999
}
.nvsheng{
  height:370rpx;
  width:370rpx;
  position: relative;
  top:-498rpx;
  left:0rpx;
  z-index: -999;
}
/* 包裹進(jìn)度條 */
.progressbar{
  position: absolute;
  bottom: 200rpx;
  height:80rpx;
  width:640rpx;
  line-height: 80rpx;
  display: flex;
}
.barprogress{
  position: relative;
  height:4rpx;
  width:450rpx;
  background: rgba(0,0,0,0.5);
  margin:auto
}
/* 真實(shí)進(jìn)度條 */
.barprogress-timely{
  position: absolute;
  top:0;
  left:0;
  z-index: 1;
  height:4rpx;
  background-color: red;
} 
/* 小圓球 */
.barcircle{
  position: absolute;
  top:-4rpx;
  right:-12rpx;
  height:12rpx;
  width:12rpx;
  border-radius: 50%;
  background-color: #fff;
}

.musicControls{
  display: flex;
  height:100rpx;
  line-height: 100rpx;
  margin-top:-30rpx;
}
.musicControls text{
  width:20%;
 font-size: 50rpx;
}
.musicControls text:nth-child(3)
{
  font-size: 65rpx;
}
.songList{
  position:fixed;
  top:400rpx;
  right:20rpx;
  width: 94%;
  background-image: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
  border-radius: 20rpx;
  z-index: 10000;
  height:calc(100vh - 400rpx)
}
.songItem{
    height:100rpx;
    line-height: 100rpx;
    color: white;

}

內(nèi)附三張圖片------右鍵可直接拿走

微信小程序音樂播放器下一首的代碼,javascript,前端,npm微信小程序音樂播放器下一首的代碼,javascript,前端,npm微信小程序音樂播放器下一首的代碼,javascript,前端,npm

播放器字體圖標(biāo)的引入------這邊就不放出來了

有需要的可以自行到阿里圖標(biāo)庫下載相關(guān)字體
[[iconfont-阿里巴巴矢量圖標(biāo)庫](https://www.iconfont.cn文章來源地址http://www.zghlxwxcb.cn/news/detail-818228.html

到了這里,關(guān)于微信小程序播放器的一些簡單功能實(shí)現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • uniapp - 微信小程序接入騰訊視頻播放器功能插件,uniapp開發(fā)微信小程序端調(diào)用引入并使用騰訊視頻播放組件完整全流程(詳細(xì)示例源碼,一鍵復(fù)制開箱即用)

    uniapp - 微信小程序接入騰訊視頻播放器功能插件,uniapp開發(fā)微信小程序端調(diào)用引入并使用騰訊視頻播放組件完整全流程(詳細(xì)示例源碼,一鍵復(fù)制開箱即用)

    在uniapp 微信小程序項(xiàng)目中,集成騰訊視頻功能插件,實(shí)現(xiàn)播放騰訊視頻效果,附帶詳細(xì)示例源碼及注釋, 你可以跟著步驟一步步來,保證幾分鐘就能快速在uniapp小程序項(xiàng)目中植入騰訊視頻功能!

    2024年02月12日
    瀏覽(95)
  • 微信小程序——【云音樂播放器】

    微信小程序——【云音樂播放器】

    目錄 第一章 開發(fā)準(zhǔn)備 一、項(xiàng)目結(jié)構(gòu) 二、新建微信小程序項(xiàng)目 第二章 標(biāo)簽頁切換 一、常用組件介紹 二、編寫頁面結(jié)構(gòu)和樣式 第三章 音樂推薦 一、組件介紹 二、編寫音樂推薦頁面結(jié)構(gòu)和樣式 第四章 播放器 一、任務(wù)分析 二、組件介紹 三、實(shí)現(xiàn)播放器功能 四、編寫播放器

    2024年02月09日
    瀏覽(26)
  • 音樂播放器微信小程序

    音樂播放器微信小程序

    一:學(xué)習(xí)目標(biāo): 掌握swiper組件、scroll-view組件的使用; 掌握image組件的使用; 掌握slider組件的使用; 掌握音頻API的使用; ?二:目錄: 1. 開發(fā)前的準(zhǔn)備 1.1?音樂小程序 項(xiàng)目展示 : 1.1.1: 音樂推薦 界面展示: 1.1.2: 播放器 界面展示: 1.1.3: 播放列表 界面展示: 1.2: 項(xiàng)目

    2024年02月05日
    瀏覽(19)
  • 微信小程序音樂播放器實(shí)踐

    微信小程序音樂播放器實(shí)踐

    1.成品展示: 實(shí)現(xiàn)搜索音樂,同步歌詞,控制播放等功能 2.設(shè)計(jì): 采用微信開發(fā)文檔中的audio組件的作為代碼原型,進(jìn)行擴(kuò)展,鏈接audio | 微信開放文檔 (qq.com) 3、具體設(shè)計(jì) 思維導(dǎo)圖 鏈接:https://pan.baidu.com/s/1whZC2xOP4HvbDMjMPA7pRQ? 提取碼:ljsb 3.1 播放界面index 3.2 索引界面list

    2024年02月11日
    瀏覽(22)
  • 《微信小程序》音樂播放器項(xiàng)目

    《微信小程序》音樂播放器項(xiàng)目

    需求:在裝有node.js的機(jī)器上使用微信開發(fā)者工具開發(fā)一個(gè)音樂播放項(xiàng)目 寫這個(gè)項(xiàng)目的時(shí)候電腦前后藍(lán)屏了5次,制作不易,希望大佬們給個(gè)雙擊,順子在這感謝啦! 展示: pages–index–index.js 01.png 02.png 02stop.png 03.png 04.png 05.png 06.png banner.jpg banner2.jpg banner3.jpg cover.jpg cover1.png

    2024年02月11日
    瀏覽(29)
  • 微信小程序?qū)崿F(xiàn)音樂播放器(1)

    微信小程序?qū)崿F(xiàn)音樂播放器(1)

    代碼涉及的主要文件有: app.json app.wxss pages/music/music.json pages/music/music.wxml pages/music/music.wxss pages/music/music.js 另外,你可能需要的圖片資源,在這里! BackgroundAudioManager實(shí)現(xiàn)背景音樂 imzusheng / netease-music-uniapp

    2024年02月09日
    瀏覽(24)
  • 微信小程序音樂播放器【含源碼】

    微信小程序音樂播放器【含源碼】

    微信小程序音樂播放器 取源碼私聊

    2024年02月06日
    瀏覽(27)
  • 微信小程序仿網(wǎng)易音樂播放器項(xiàng)目

    微信小程序仿網(wǎng)易音樂播放器項(xiàng)目

    主頁樣式 播放頁樣式 搜索頁樣式 排行榜頁樣式 小控件樣式 網(wǎng)易云音樂API接口 后端接口,使用node寫的,使用了網(wǎng)易云音樂API: 封裝的api文件 主頁面功能點(diǎn) banner,滑動(dòng)菜單欄采用微信的API( swiper 與 scroll-view )進(jìn)行開發(fā) 滑動(dòng)到底部重新獲取后續(xù)的歌曲,使用onReachBottom周期

    2024年02月06日
    瀏覽(30)
  • java微信小程序音樂播放器分享系統(tǒng)

    java微信小程序音樂播放器分享系統(tǒng)

    隨著我國經(jīng)濟(jì)迅速發(fā)展,人們對(duì)手機(jī)的需求越來越大,各種手機(jī)軟件也都在被廣泛應(yīng)用,但是對(duì)于手機(jī)進(jìn)行數(shù)據(jù)信息管理,對(duì)于手機(jī)的各種軟件也是備受用戶的喜愛,音樂播放器小程序被用戶普遍使用,為方便用戶能夠可以隨時(shí)進(jìn)行音樂播放器小程序的數(shù)據(jù)信息管理,特開發(fā)了基于音樂

    2024年02月11日
    瀏覽(25)
  • 基于微信小程序的音樂播放器設(shè)計(jì)

    基于微信小程序的音樂播放器設(shè)計(jì)

    目 錄 1緒論 1 1.1選題背景及意義 1 1.2發(fā)展現(xiàn)狀 1 1.2.1什么是微信小程序 1 1.2.2小程序市場的現(xiàn)狀 4 1.3研究主要內(nèi)容 4 2系統(tǒng)技術(shù) 5 2.1 Java語言 5 2.2 SSM框架 6 2.3 Vue.js框架 7 2.4 Eclipse開發(fā)工具 8 2.5數(shù)據(jù)庫 9 2.6系統(tǒng)開發(fā)環(huán)境概述 10 3系統(tǒng)分析 12 3.1 功能需求(用例圖分析) 12 3.1.1 網(wǎng)絡(luò)音

    2024年02月11日
    瀏覽(18)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包