app.json:
{
"pages":[
"pages/music1/music1",
"pages/music2/music2",
"pages/music3/music3",
"pages/music4/music4",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "微音樂",
"navigationBarTextStyle":"black"
},
"tabBar": {
"color": "#818181",
"backgroundColor": "black",
"selectedColor": "green",
"list": [{
"pagePath": "pages/music1/music1",
"text": "音樂列表",
"iconPath": "image/music.jpg",
"selectedIconPath": "/image/music-s.jpg"
},{
"pagePath": "pages/music2/music2",
"iconPath": "/image/playing.jpg",
"selectedIconPath": "/image/playing-s.jpg",
"text": "正在播放"
},{
"pagePath": "pages/music4/music4",
"iconPath": "/image/search.jpg",
"selectedIconPath": "/image/search-s.jpg",
"text": "搜索"
}]
}
}
config.js
(function(module){
var exports=module.exports={};
var appid = 63888;
var secert ="e628f91c466942bab3b7a5c838c742d8";
var param="?showapi_appid="+appid+"&showapi_sign="+secert;
var hotUrl="http://route.showapi.com/213-4"+param;
var searchByNameUrl = "http://route.showapi.com/213-1"+param;
var searchByIdUrl = "http://route.showapi.com/213-2"+param;
module.exports={
config:{
hotUrl:hotUrl,
searchByNameUrl:searchByNameUrl,
searchByIdUrl: searchByIdUrl
}
}
})(module);
music1.wxml
<view class='container'>
<view class='rank-list'>
<block wx:for="{{ranks}}" wx:key="{{item.type}}">
<view class='rank-item'>
<navigator url='/pages/music3/music3?type={{item.type}}' class='text'>{{item.text}}</navigator>
<view class='arrow'></view>
</view>
</block>
</view>
</view>
music1.js
// pages/music1/music1.js
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
ranks:[
{ type: 26, text: "熱歌" },
{ type: 23, text: "銷量" },
{ type: 18, text: "民謠" },
{ type: 19, text: "搖滾" },
{ type: 5, text: "內(nèi)地" },
{ type: 6, text: "港臺" },
{ type: 16, text: "韓國" },
{ type: 17, text: "日本" },
{ type: 3, text: "歐美" },
]
},
})
music2.wxml
<!--pages/music2/music2.wxml-->
<view class="playing container">
<view class="thumbnail">
<image src="{{song.albumpic_big}}" />
</view>
<view class="detail">
<view class="title">{{song.songname}}</view>
<view class="author">{{song.singername}}</view>
<view class="action">
<view class="act-toggle" bindtap="playToggle">
<image src="/image/{{isPlaying ? 'pause' : 'play'}}.jpg" />
</view>
</view>
</view>
</view>
music2.js
var config = require('../../config.js'); //導(dǎo)入配置文件
// pages/music2/music2.js
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
song: {}, //傳入的歌曲信息
isPlaying: false, //播放狀態(tài)
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
var self = this;
var songid = options.songid; //獲取頁面跳轉(zhuǎn)傳過來的參數(shù)(歌曲對象)
if (songid === undefined) { //未傳入歌曲ID
var curSong = wx.getStorageSync('curSong') || {}; //從緩存中獲取歌曲
if (curSong === undefined) { //緩存中無歌曲
var song = { songname: '未選擇歌曲' }; //顯示未選擇歌曲
this.setData({
song: song
})
} else {
this.setData({
song: curSong
});
}
} else {
var songlist = wx.getStorageSync('songlist') || []; //從緩存中取出歌曲列表
//在歌曲列表中查找songid指定的歌曲
for (var i = 0; i < songlist.length; i++) {
if (songlist[i].songid == songid) { //找到對應(yīng)的歌曲
this.setData({
song: songlist[i] //更新歌曲
});
break;
}
}
//緩存正在播放的歌曲
wx.setStorageSync('curSong', this.data.song);
}
},
playToggle: function () {
var self = this;
//沒有歌曲要播放,則直接退出
if (this.data.song.songname == '未選擇歌曲') {
return;
}
if (this.data.isPlaying) { //正在播放
wx.stopBackgroundAudio(); //停止播放歌曲
} else {//未播放,則開始播放
//播放歌曲
wx.playBackgroundAudio({
dataUrl: this.data.song.url || this.data.song.m4a,
success: function (res) { }
})
}
//更新播放狀態(tài)
this.setData({
isPlaying: !this.data.isPlaying
});
},
})
music3.wxml
<!--pages/music3/music3.wxml-->
<scroll-view scroll-y='true'>
<view class='board'>
<image src='{{board}}'></image>
</view>
<view class='songlist'>
<block wx:for="{{songlist}}" wx:key="song_id">
<view class='songitem'>
<navigator url="/pages/music2/music2?songid={{item.songid}}" class='song-play'><image src='image/playing.jpg'></image></navigator>
<navigator url="/pages/music2/music2?songid={{item.songid}}" class='song-detail'>
<view class='song-title'>{{item.songname}}</view>
<view class='song-subtitle'>{{item.singername}}-{{item.seconds}}</view>
</navigator>
</view>
</block>
</view>
<loading hidden="{{!loading}}">
正在加載音樂....
</loading>
</scroll-view>
music3.js
var condig=require('../../config.js');
var formatSeconds=function(value){
var time=parseFloat(value);
var m=Math.floor(time/60);
var s=time-m*60;
return [m,s].map(formatNumber).join(':');
function formatNumber(n){
n=n.toString()
return n[1]?n:'+n'
}
}
// pages/music3/music3.js
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
board:'',
songlist:[],
loading:false,
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
var self=this;
var topid=options.type;
this.setData({
loading:true
})
wx.request({
url:config.config.hotUrl,
data:{topid:topid},
success:function(e){
if(e.statusCode==200){
var songlist=e.data.showapi_res_body.pagebean.songlist;
for(var i=0;i<songlist.length;i++)
{
songlist[i].secondds=formatSeconds(songlist[i].seconds);
}
self.setData({
board:e.data.showapi_res_body.pagebean.songlist[0].albumpic_big,
songlist:songlist,
loading:false
});
wx.setStorageSync('songlist',songlist);
}
}
});
},
})
編譯后,如下圖:
點擊后報錯,信息如下:
大佬們幫忙看看 謝謝
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。