blob: d064fb546ce68a493258709270fb8db101ea2484 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// omg I am tired of code
const { getPlayer } = require('./players')
const { getDownloaderFor } = require('./downloaders')
const EventEmitter = require('events')
class InternalApp extends EventEmitter {
constructor() {
super()
this.player = null
}
async setup() {
this.player = await getPlayer()
}
async startPlaying(arg) {
this.player.playFile(await this.download(arg))
}
stopPlaying() {
this.player.kill()
}
seekAhead(seconds) {
this.player.seekAhead(seconds)
}
seekBehind(seconds) {
this.player.seekBehind(seconds)
}
togglePause() {
this.player.togglePause()
}
download(arg) {
return getDownloaderFor(arg)(arg)
}
}
async function main() {
const internalApp = new InternalApp()
await internalApp.setup()
await internalApp.startPlaying('http://billwurtz.com/cable-television.mp3')
await new Promise(r => setTimeout(r, 2000))
internalApp.togglePause()
await new Promise(r => setTimeout(r, 1000))
internalApp.togglePause()
await new Promise(r => setTimeout(r, 2000))
internalApp.stopPlaying()
}
main().catch(err => console.error(err))
|