|
7 | 7 |
|
8 | 8 | public class AudioAsset {
|
9 | 9 |
|
10 |
| - private final String TAG = "AudioAsset"; |
11 |
| - |
12 |
| - private ArrayList<AudioDispatcher> audioList; |
13 |
| - private int playIndex = 0; |
14 |
| - private String assetId; |
15 |
| - private NativeAudio owner; |
16 |
| - |
17 |
| - AudioAsset( |
18 |
| - NativeAudio owner, |
19 |
| - String assetId, |
20 |
| - AssetFileDescriptor assetFileDescriptor, |
21 |
| - int audioChannelNum, |
22 |
| - float volume |
23 |
| - ) |
24 |
| - throws Exception { |
25 |
| - audioList = new ArrayList<>(); |
26 |
| - this.owner = owner; |
27 |
| - this.assetId = assetId; |
28 |
| - |
29 |
| - if (audioChannelNum < 0) { |
30 |
| - audioChannelNum = 1; |
| 10 | + private final String TAG = "AudioAsset"; |
| 11 | + |
| 12 | + private ArrayList<AudioDispatcher> audioList; |
| 13 | + private int playIndex = 0; |
| 14 | + private String assetId; |
| 15 | + private NativeAudio owner; |
| 16 | + |
| 17 | + AudioAsset(NativeAudio owner, String assetId, AssetFileDescriptor assetFileDescriptor, int audioChannelNum, float volume) |
| 18 | + throws Exception { |
| 19 | + audioList = new ArrayList<>(); |
| 20 | + this.owner = owner; |
| 21 | + this.assetId = assetId; |
| 22 | + |
| 23 | + if (audioChannelNum < 0) { |
| 24 | + audioChannelNum = 1; |
| 25 | + } |
| 26 | + |
| 27 | + for (int x = 0; x < audioChannelNum; x++) { |
| 28 | + AudioDispatcher audioDispatcher = new AudioDispatcher(assetFileDescriptor, volume); |
| 29 | + audioList.add(audioDispatcher); |
| 30 | + if (audioChannelNum == 1) audioDispatcher.setOwner(this); |
| 31 | + } |
31 | 32 | }
|
32 | 33 |
|
33 |
| - for (int x = 0; x < audioChannelNum; x++) { |
34 |
| - AudioDispatcher audioDispatcher = new AudioDispatcher( |
35 |
| - assetFileDescriptor, |
36 |
| - volume |
37 |
| - ); |
38 |
| - audioList.add(audioDispatcher); |
39 |
| - if (audioChannelNum == 1) audioDispatcher.setOwner(this); |
| 34 | + public void dispatchComplete() { |
| 35 | + this.owner.dispatchComplete(this.assetId); |
40 | 36 | }
|
41 |
| - } |
42 | 37 |
|
43 |
| - public void dispatchComplete() { |
44 |
| - this.owner.dispatchComplete(this.assetId); |
45 |
| - } |
| 38 | + public void play(Double time, Callable<Void> callback) throws Exception { |
| 39 | + AudioDispatcher audio = audioList.get(playIndex); |
46 | 40 |
|
47 |
| - public void play(Double time, Callable<Void> callback) throws Exception { |
48 |
| - AudioDispatcher audio = audioList.get(playIndex); |
49 |
| - |
50 |
| - if (audio != null) { |
51 |
| - audio.play(time, callback); |
52 |
| - playIndex++; |
53 |
| - playIndex = playIndex % audioList.size(); |
| 41 | + if (audio != null) { |
| 42 | + audio.play(time, callback); |
| 43 | + playIndex++; |
| 44 | + playIndex = playIndex % audioList.size(); |
| 45 | + } |
54 | 46 | }
|
55 |
| - } |
56 | 47 |
|
57 |
| - public double getDuration() { |
58 |
| - if (audioList.size() != 1) return 0; |
| 48 | + public double getDuration() { |
| 49 | + if (audioList.size() != 1) return 0; |
59 | 50 |
|
60 |
| - AudioDispatcher audio = audioList.get(playIndex); |
| 51 | + AudioDispatcher audio = audioList.get(playIndex); |
61 | 52 |
|
62 |
| - if (audio != null) { |
63 |
| - return audio.getDuration(); |
| 53 | + if (audio != null) { |
| 54 | + return audio.getDuration(); |
| 55 | + } |
| 56 | + return 0; |
64 | 57 | }
|
65 |
| - return 0; |
66 |
| - } |
67 | 58 |
|
68 |
| - public double getCurrentPosition() { |
69 |
| - if (audioList.size() != 1) return 0; |
| 59 | + public double getCurrentPosition() { |
| 60 | + if (audioList.size() != 1) return 0; |
70 | 61 |
|
71 |
| - AudioDispatcher audio = audioList.get(playIndex); |
| 62 | + AudioDispatcher audio = audioList.get(playIndex); |
72 | 63 |
|
73 |
| - if (audio != null) { |
74 |
| - return audio.getCurrentPosition(); |
| 64 | + if (audio != null) { |
| 65 | + return audio.getCurrentPosition(); |
| 66 | + } |
| 67 | + return 0; |
75 | 68 | }
|
76 |
| - return 0; |
77 |
| - } |
78 | 69 |
|
79 |
| - public boolean pause() throws Exception { |
80 |
| - boolean wasPlaying = false; |
| 70 | + public boolean pause() throws Exception { |
| 71 | + boolean wasPlaying = false; |
81 | 72 |
|
82 |
| - for (int x = 0; x < audioList.size(); x++) { |
83 |
| - AudioDispatcher audio = audioList.get(x); |
84 |
| - wasPlaying |= audio.pause(); |
85 |
| - } |
| 73 | + for (int x = 0; x < audioList.size(); x++) { |
| 74 | + AudioDispatcher audio = audioList.get(x); |
| 75 | + wasPlaying |= audio.pause(); |
| 76 | + } |
86 | 77 |
|
87 |
| - return wasPlaying; |
88 |
| - } |
| 78 | + return wasPlaying; |
| 79 | + } |
89 | 80 |
|
90 |
| - public void resume() throws Exception { |
91 |
| - if (audioList.size() > 0) { |
92 |
| - AudioDispatcher audio = audioList.get(0); |
| 81 | + public void resume() throws Exception { |
| 82 | + if (audioList.size() > 0) { |
| 83 | + AudioDispatcher audio = audioList.get(0); |
93 | 84 |
|
94 |
| - if (audio != null) { |
95 |
| - audio.resume(); |
96 |
| - } |
| 85 | + if (audio != null) { |
| 86 | + audio.resume(); |
| 87 | + } |
| 88 | + } |
97 | 89 | }
|
98 |
| - } |
99 | 90 |
|
100 |
| - public void stop() throws Exception { |
101 |
| - for (int x = 0; x < audioList.size(); x++) { |
102 |
| - AudioDispatcher audio = audioList.get(x); |
| 91 | + public void stop() throws Exception { |
| 92 | + for (int x = 0; x < audioList.size(); x++) { |
| 93 | + AudioDispatcher audio = audioList.get(x); |
103 | 94 |
|
104 |
| - if (audio != null) { |
105 |
| - audio.stop(); |
106 |
| - } |
| 95 | + if (audio != null) { |
| 96 | + audio.stop(); |
| 97 | + } |
| 98 | + } |
107 | 99 | }
|
108 |
| - } |
109 | 100 |
|
110 |
| - public void loop() throws Exception { |
111 |
| - AudioDispatcher audio = audioList.get(playIndex); |
| 101 | + public void loop() throws Exception { |
| 102 | + AudioDispatcher audio = audioList.get(playIndex); |
112 | 103 |
|
113 |
| - if (audio != null) { |
114 |
| - audio.loop(); |
115 |
| - playIndex++; |
116 |
| - playIndex = playIndex % audioList.size(); |
| 104 | + if (audio != null) { |
| 105 | + audio.loop(); |
| 106 | + playIndex++; |
| 107 | + playIndex = playIndex % audioList.size(); |
| 108 | + } |
117 | 109 | }
|
118 |
| - } |
119 | 110 |
|
120 |
| - public void unload() throws Exception { |
121 |
| - this.stop(); |
| 111 | + public void unload() throws Exception { |
| 112 | + this.stop(); |
122 | 113 |
|
123 |
| - for (int x = 0; x < audioList.size(); x++) { |
124 |
| - AudioDispatcher audio = audioList.get(x); |
| 114 | + for (int x = 0; x < audioList.size(); x++) { |
| 115 | + AudioDispatcher audio = audioList.get(x); |
125 | 116 |
|
126 |
| - if (audio != null) { |
127 |
| - audio.unload(); |
128 |
| - } |
129 |
| - } |
| 117 | + if (audio != null) { |
| 118 | + audio.unload(); |
| 119 | + } |
| 120 | + } |
130 | 121 |
|
131 |
| - audioList.clear(); |
132 |
| - } |
| 122 | + audioList.clear(); |
| 123 | + } |
133 | 124 |
|
134 |
| - public void setVolume(float volume) throws Exception { |
135 |
| - for (int x = 0; x < audioList.size(); x++) { |
136 |
| - AudioDispatcher audio = audioList.get(x); |
| 125 | + public void setVolume(float volume) throws Exception { |
| 126 | + for (int x = 0; x < audioList.size(); x++) { |
| 127 | + AudioDispatcher audio = audioList.get(x); |
137 | 128 |
|
138 |
| - if (audio != null) { |
139 |
| - audio.setVolume(volume); |
140 |
| - } |
| 129 | + if (audio != null) { |
| 130 | + audio.setVolume(volume); |
| 131 | + } |
| 132 | + } |
141 | 133 | }
|
142 |
| - } |
143 |
| - |
144 |
| - public boolean isPlaying() throws Exception { |
145 |
| - if (audioList.size() != 1) return false; |
146 | 134 |
|
147 |
| - return audioList.get(playIndex).isPlaying(); |
148 |
| - } |
| 135 | + public boolean isPlaying() throws Exception { |
| 136 | + if (audioList.size() != 1) return false; |
149 | 137 |
|
| 138 | + return audioList.get(playIndex).isPlaying(); |
| 139 | + } |
150 | 140 | }
|
0 commit comments