|
@@ -2,6 +2,9 @@
|
|
|
const app = getApp()
|
|
|
const util = require("../../utils/util")
|
|
|
const urlDef = require("../../utils/urls")
|
|
|
+
|
|
|
+// const recordManager = wx.getRecorderManager() //录音对象
|
|
|
+const audioContext = wx.createInnerAudioContext() //音频播放对象
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -15,7 +18,7 @@ Page({
|
|
|
videoContext: '',
|
|
|
curAudio: '',
|
|
|
curAudioIndex: -1,
|
|
|
- audioPause: 0,
|
|
|
+ audioPause: false,
|
|
|
doTaskFlag: false,
|
|
|
entity: null,
|
|
|
teacherFace: '/images/head.png',
|
|
@@ -72,31 +75,33 @@ Page({
|
|
|
urls: list
|
|
|
})
|
|
|
},
|
|
|
- audioShow: function (e) {
|
|
|
- if (this.data.audioPause == 0 && this.data.curAudioIndex != e.currentTarget.dataset.index) {//播放语音,切换
|
|
|
- this.setData({
|
|
|
- curAudio: ""
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- curAudioIndex: e.currentTarget.dataset.index,
|
|
|
- curAudio: e.currentTarget.dataset.url,
|
|
|
|
|
|
- })
|
|
|
- this.audioContext.play()
|
|
|
+ showAudio:function(e){
|
|
|
+ const index = e.currentTarget.dataset.index
|
|
|
+ if(this.data.curAudioIndex != index){
|
|
|
this.setData({
|
|
|
- audioPause: 0
|
|
|
+ curAudioIndex: index,
|
|
|
})
|
|
|
- } else if (this.data.audioPause == 1 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停后恢复播放
|
|
|
- this.audioContext.play()
|
|
|
- this.setData({
|
|
|
- audioPause: 0
|
|
|
- })
|
|
|
- } else if (this.data.audioPause == 0 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停播放
|
|
|
- this.audioContext.pause()
|
|
|
- this.setData({
|
|
|
- audioPause: 1
|
|
|
+ audioContext.src = this.data.audioList[index]
|
|
|
+ audioContext.play()
|
|
|
+ audioContext.onEnded((res)=>{
|
|
|
+ this.setData({
|
|
|
+ curAudioIndex: '-1',
|
|
|
+ })
|
|
|
})
|
|
|
- }
|
|
|
+ }else{
|
|
|
+ if(this.data.audioPause){
|
|
|
+ audioContext.play()
|
|
|
+ this.setData({
|
|
|
+ audioPause: false
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ audioContext.pause()
|
|
|
+ this.setData({
|
|
|
+ audioPause: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
bindended: function () {
|
|
@@ -119,7 +124,7 @@ Page({
|
|
|
onLoad: function (options) {
|
|
|
let id = options.id;
|
|
|
this.setData({ homeworkId: id });
|
|
|
- this.audioContext = wx.createAudioContext('audio-play')
|
|
|
+ // this.audioContext = wx.createAudioContext('audio-play')
|
|
|
this.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。
|
|
|
const type = options.type
|
|
|
if (type == 0) {
|