[AppleScript] 纯文本查看 复制代码
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
let bsurl = 'https://poche.fm/api/app/playlists'
var common = require('../../../utils/util.js');
let seek = 0
let defaultdata = {
winWidth: 0,
winHeight: 0,
listHeight: 0,
// tab切换
currentTab: 0,
// 播放列表
playlists: [],
tracks: [],
coverImgUrl: "../../../imgs/icon.jpg",
nowPlayingTitle:"请选择歌曲",
nowPlayingArtist: "",
playing:false,
playtime: '00:00',
duration: '00:00',
percent: 1,
lrc: [],
lrcindex: 0,
showlrc: false,
disable: false,
downloadPercent: 0,
curIndex: 0,
initial: true,
shuffle: 1,
music: {}
}
//获取应用实例
let app = getApp()
Page({
data: defaultdata,
onLoad: function(options) {
var that = this;
wx.request({
url: bsurl,
success: function (res) {
that.setData({
listHeight: res.data.length * 230,
playlists: res.data,
loadingHide:true
})
}
})
//获取系统信息
wx.getSystemInfo( {
success: function( res ) {
that.setData( {
winWidth: res.windowWidth,
winHeight: res.windowHeight
})
}
})
// 获取上次播放数据
let index = wx.getStorageSync('curIndex')
let tracks = wx.getStorageSync('tracks')
if (tracks) {
let track = tracks[index]
that.setData( {
curIndex: index,
tracks: tracks,
coverImgUrl:track.cover,
nowPlayingArtist: track.artist,
nowPlayingTitle: track.name,
})
}
//监听停止,自动下一首
wx.onBackgroundAudioStop(function(){
that.playnext();
})
},
bindChange: function(e) {
var that = this;
that.setData( { currentTab: e.detail.current });
},
swichNav: function(e) {
var that = this;
if( this.data.currentTab === e.target.dataset.current ) {
return false;
} else {
that.setData( {
currentTab: e.target.dataset.current
})
}
},
// 跳转下一页
tracks: function(event) {
var index = event.currentTarget.id
var playlist = this.data.playlists[index]
var p = playlist.id
var title = playlist.title
wx.navigateTo({
url: '../tracks/index?id=' + p + '&title=' + title
})
},
// 接收点击数据
changeData: function(tracks, index) {
var curMusic = tracks[index]
this.setData({
curIndex: index,
tracks: tracks,
coverImgUrl:curMusic.cover,
nowPlayingArtist: curMusic.artist,
nowPlayingTitle: curMusic.name,
playing: true,
music: curMusic
})
app.globalData.curplay.id = curMusic.id
//存储当前播放
wx.setStorageSync("curIndex", index)
wx.setStorageSync("tracks", tracks)
app.seekmusic(1)
},
//播放方法
playingtoggle:function(){
var that = this
if (this.data.initial) {
// this.play(this.data.tracks, this.data.curIndex)
this.setData({
initial: false
})
app.seekmusic(1)
return
}
if (this.data.playing) {
that.setData({
playing: false
})
app.stopmusic(1)
} else {
app.seekmusic(1, function () {
that.setData({
playing: true
})
}, app.globalData.currentPosition)
}
},
playnext: function (e) {
if (this.data.initial) {
this.setData({
initial: false
})
}
let shuffle = this.data.shuffle
let count = this.data.tracks.length
let lastIndex = parseInt(this.data.curIndex)
if (shuffle == 3) {
//随机播放
lastIndex = Math.floor(Math.random() * count)
} else if (shuffle == 1) {
if (lastIndex == count - 1) {
lastIndex = 0
} else {
lastIndex = lastIndex + 1
}
}
this.changeData(this.data.tracks, lastIndex)
},
playprev: function (e) {
if (this.data.initial) {
this.setData({
initial: false
})
}
let shuffle = this.data.shuffle
let lastIndex = parseInt(this.data.curIndex)
let count = this.data.tracks.length
if (shuffle == 3) {
//随机播放
lastIndex = Math.floor(Math.random() * count)
} else if (shuffle == 1) {
if (lastIndex == 0) {
lastIndex = count - 1
} else {
lastIndex = lastIndex - 1
}
}
this.changeData(this.data.tracks, lastIndex)
},
playshuffle: function() {
if (this.data.shuffle == 1) {
this.setData({
shuffle: 2
})
return
}
if (this.data.shuffle == 2) {
this.setData({
shuffle: 3
})
return
}
if (this.data.shuffle == 3) {
this.setData({
shuffle: 1
})
}
},
onShow: function () {
var that = this
app.globalData.playtype = this.data.shuffle
common.playAlrc(that, app);
seek = setInterval(function () {
common.playAlrc(that, app);
}, 1000)
},
})
|