这个还是看自己写的练习文件,这个太一半了
这个是写小程序的时候。npm的天坑 让我怎么都爬不出来。 所以还是决定自己用写moment.js。 time的文件在github
// miniprogram/pages/song/song.js
import { request } from "../../utils/util";
import {formatDuring} from "../../utils/time"
// import moment from 'moment'; 这个真的麻烦 不弄了 直接写
var appInstance = getApp();
Page({
data: {
currentWidth:30,
playing:false,
songContent:[],
songUrl:'',
durationTime:'00:00',
currentTime:'03:00',
},
onLoad: function (options) {
let songId=options.songId;
this.getSongContent(songId);
this.getSongUrl(songId);
},
getSongUrl: async function(id){
let result= await request('/song/url',{id})
this.setData({
songUrl:result.data[0].url
})
console.log("setting url",this.data)
}
,
getSongContent: async function(id){
let result= await request('/song/detail',{ids:id})
console.log("song content",result.songs[0])
let dt= result.songs[0].dt;
let {minutes , seconds }=formatDuring(dt)
//console.log(parseInt(minutes),parseInt(seconds))
this.setData({
songContent:result.songs[0],
durationTime:parseInt(minutes)+":"+parseInt(seconds)
})
wx.setNavigationBarTitle({
title: this.data.songContent.name+" "+this.data.songContent.ar[0].name
})
},
controlMusic:function(){
this.setData({
playing:!this.data.playing
})
this.playMusic()
},
playMusic(){
console.log(this.data.songUrl)
let backgroundAudioManager=wx.getBackgroundAudioManager()
let {songUrl,songContent}= this.data
if(this.data.playing){
backgroundAudioManager.src = songUrl;
backgroundAudioManager.title = songContent.name;
}else{
backgroundAudioManager.pause();
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})