blob: 64c82159f7d1b5c1432cdcde804e58ba06107d00 (
plain)
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
|
import * as types from '../../types'
import { store, history, dispatch } from '../../store'
import actions from '../../actions'
import { session } from '../../session'
const audioPlayer = document.createElement('audio')
audioPlayer.src = '/static/data_store/peaks/animismA080720.mp3'
audioPlayer.addEventListener('loadedmetadata', () => {
console.log('audio duration:', audioPlayer.duration)
dispatch({ type: types.align.set_display_setting, key: 'duration', value: audioPlayer.duration })
})
audioPlayer.addEventListener('play', () => {
dispatch({ type: types.audio.play })
})
audioPlayer.addEventListener('pause', () => {
dispatch({ type: types.audio.pause })
})
audioPlayer.addEventListener('timeupdate', () => {
dispatch({ type: types.audio.update_time, play_ts: audioPlayer.currentTime })
})
export const play = () => dispatch => {
audioPlayer.play()
}
export const pause = () => dispatch => {
audioPlayer.pause()
}
export const seek = play_ts => dispatch => {
audioPlayer.currentTime = play_ts
}
export const jump = delta_ts => dispatch => {
audioPlayer.currentTime += delta_ts
}
export const toggle = () => dispatch => {
if (store.getState().audio.playing) {
pause()(dispatch)
} else {
play()(dispatch)
}
}
|