1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| function operateAudioPlayer (audioId, pageId, type, data) {
| UniServiceJSBridge.publishHandler(pageId + '-audio-' + audioId, {
| audioId,
| type,
| data
| }, pageId)
| }
|
| class AudioContext {
| constructor (id, pageId) {
| this.id = id
| this.pageId = pageId
| }
|
| setSrc (src) {
| operateAudioPlayer(this.id, this.pageId, 'setSrc', {
| src
| })
| }
|
| play () {
| operateAudioPlayer(this.id, this.pageId, 'play')
| }
|
| pause () {
| operateAudioPlayer(this.id, this.pageId, 'pause')
| }
|
| seek (position) {
| operateAudioPlayer(this.id, this.pageId, 'seek', {
| position
| })
| }
| }
|
| export function createAudioContext (id, context) {
| if (context) {
| return new AudioContext(id, context.$page.id)
| }
| const app = getApp()
| if (app.$route && app.$route.params.__id__) {
| return new AudioContext(id, app.$route.params.__id__)
| } else {
| UniServiceJSBridge.emit('onError', 'createAudioContext:fail')
| }
| }
|
|