1import * as AUDIOPLAYER from 'AUDIOPLAYER';
2import * as events from 'events'
3
4export default class audioplayer extends events.EventEmitter {
5    constructor(){
6        super();
7        this._onState();
8    }
9
10    static play(source, callback) {
11        if (!source || !callback) {
12            throw new Error('invalid params');
13        }
14        console.log('play ' + source);
15        return AUDIOPLAYER.play(source, callback);
16    };
17
18    static pause() {
19        return AUDIOPLAYER.pause();
20    };
21
22    static resume() {
23        return AUDIOPLAYER.resume();
24    };
25
26    static stop() {
27        return AUDIOPLAYER.stop();
28    };
29
30    static seekto(seconds) {
31        if (seconds < 0) {
32            throw new Error('invalid params');
33        }
34        return AUDIOPLAYER.seekto(seconds);
35    };
36
37    static getPosition() {
38        return AUDIOPLAYER.getPosition();
39    };
40
41    static getDuration() {
42        return AUDIOPLAYER.getDuration();
43    };
44
45    static getState() {
46        return AUDIOPLAYER.getState();
47    };
48
49    static _onState() {
50        AUDIOPLAYER.onState(function(state) {
51            this.emit('stateChange', state);
52        }.bind(this));
53    };
54
55    static listPlay(sourcelist, callback) {
56        if (!sourcelist || !callback) {
57            throw new Error('invalid params');
58        }
59        return AUDIOPLAYER.listPlay(sourcelist, callback);
60    };
61
62    static listPlayStop() {
63        return AUDIOPLAYER.listPlayStop();
64    };
65
66    static setVolume(volume) {
67        if (volume < 0) {
68            throw new Error('invalid params');
69        }
70        return AUDIOPLAYER.setVolume(volume);
71    };
72
73    static getVolume() {
74        return AUDIOPLAYER.getVolume();
75    };
76}