newpage(index) {
this.$u.route({
url: 'pages/componentsD/playpage/index',
params: {
//传递参数
id:index,
}
})
},
上面是负责跳转页面
下面是跳转后的播放页面
<script>
export default {
data() {
return {
cur: 0,
list: [],
innerAudioContext: this.$innerAudioContext,
ifplay: true,
percent: 0,
duration: 300,
currentTime: 0,
seek: true,
oldsrc: '',
newsrc: '',
episodes: null,
// loading:false
}
},
onLoad(option) {
this.oldsrc = this.innerAudioContext.src;
console.log('old1-' + this.oldsrc);
if (option.id == 1) {
this.episodes = 1;
} else {
this.episodes = 2;
}
this.getMusic();
},
methods: {
getMusic() {
uni.request({
url: 'http://10.40.16.51:8080/Test/selectDetail/' + this.episodes, //仅为示例,并非真实接口地址。
data: {},
header: {},
success: (res) => {
this.innerAudioContext.src = res.data.soundSource;
console.log('old-' + this.innerAudioContext.src);
this.newsrc = res.data.soundSource;
console.log('new-' + this.newsrc);
if (this.oldsrc == this.newsrc) {
console.log('一样');
this.percent = this.innerAudioContext.startTime;
this.innerAudioContext.play();
this.ifplay = false;
} else {
console.log('不一样');
this.percent = 0;
this.innerAudioContext.startTime = 0;
this.innerAudioContext.currentTime = 0;
}
}
});
// this.innerAudioContext = this.$innerAudioContext;
},
//以下是需要改正部分
next() {
// this.innerAudioContext.pause()
this.innerAudioContext.src=this.$innerAudioContext.src
this.episodes=this.episodes+1
this.getMusic()
this.innerAudioContext.play()
console.log('下一首' + this.episodes);
console.log('-----' + this.innerAudioContext.src);
},
main.js页面
Vue.prototype.$innerAudioContext=uni.createInnerAudioContext();