Skip to content

Commit 115d241

Browse files
authored
chore: fix and run fmt script (#85)
1 parent 01ffd1f commit 115d241

File tree

15 files changed

+754
-816
lines changed

15 files changed

+754
-816
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ isPlaying(options: { assetId: string; }) => Promise<{ isPlaying: boolean; }>
373373
### addListener('complete', ...)
374374

375375
```typescript
376-
addListener(eventName: "complete", listenerFunc: (event: { assetId: string; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
376+
addListener(eventName: 'complete', listenerFunc: (event: { assetId: string; }) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
377377
```
378378

379379
Listen for asset completed playing event

android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
@RunWith(AndroidJUnit4.class)
1717
public class ExampleInstrumentedTest {
1818

19-
@Test
20-
public void useAppContext() throws Exception {
21-
// Context of the app under test.
22-
Context appContext = InstrumentationRegistry
23-
.getInstrumentation()
24-
.getTargetContext();
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
2523

26-
assertEquals("com.getcapacitor.android", appContext.getPackageName());
27-
}
24+
assertEquals("com.getcapacitor.android", appContext.getPackageName());
25+
}
2826
}

android/src/main/java/com/getcapacitor/community/audio/AudioAsset.java

+95-105
Original file line numberDiff line numberDiff line change
@@ -7,144 +7,134 @@
77

88
public class AudioAsset {
99

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+
}
3132
}
3233

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);
4036
}
41-
}
4237

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);
4640

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+
}
5446
}
55-
}
5647

57-
public double getDuration() {
58-
if (audioList.size() != 1) return 0;
48+
public double getDuration() {
49+
if (audioList.size() != 1) return 0;
5950

60-
AudioDispatcher audio = audioList.get(playIndex);
51+
AudioDispatcher audio = audioList.get(playIndex);
6152

62-
if (audio != null) {
63-
return audio.getDuration();
53+
if (audio != null) {
54+
return audio.getDuration();
55+
}
56+
return 0;
6457
}
65-
return 0;
66-
}
6758

68-
public double getCurrentPosition() {
69-
if (audioList.size() != 1) return 0;
59+
public double getCurrentPosition() {
60+
if (audioList.size() != 1) return 0;
7061

71-
AudioDispatcher audio = audioList.get(playIndex);
62+
AudioDispatcher audio = audioList.get(playIndex);
7263

73-
if (audio != null) {
74-
return audio.getCurrentPosition();
64+
if (audio != null) {
65+
return audio.getCurrentPosition();
66+
}
67+
return 0;
7568
}
76-
return 0;
77-
}
7869

79-
public boolean pause() throws Exception {
80-
boolean wasPlaying = false;
70+
public boolean pause() throws Exception {
71+
boolean wasPlaying = false;
8172

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+
}
8677

87-
return wasPlaying;
88-
}
78+
return wasPlaying;
79+
}
8980

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);
9384

94-
if (audio != null) {
95-
audio.resume();
96-
}
85+
if (audio != null) {
86+
audio.resume();
87+
}
88+
}
9789
}
98-
}
9990

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);
10394

104-
if (audio != null) {
105-
audio.stop();
106-
}
95+
if (audio != null) {
96+
audio.stop();
97+
}
98+
}
10799
}
108-
}
109100

110-
public void loop() throws Exception {
111-
AudioDispatcher audio = audioList.get(playIndex);
101+
public void loop() throws Exception {
102+
AudioDispatcher audio = audioList.get(playIndex);
112103

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+
}
117109
}
118-
}
119110

120-
public void unload() throws Exception {
121-
this.stop();
111+
public void unload() throws Exception {
112+
this.stop();
122113

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);
125116

126-
if (audio != null) {
127-
audio.unload();
128-
}
129-
}
117+
if (audio != null) {
118+
audio.unload();
119+
}
120+
}
130121

131-
audioList.clear();
132-
}
122+
audioList.clear();
123+
}
133124

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);
137128

138-
if (audio != null) {
139-
audio.setVolume(volume);
140-
}
129+
if (audio != null) {
130+
audio.setVolume(volume);
131+
}
132+
}
141133
}
142-
}
143-
144-
public boolean isPlaying() throws Exception {
145-
if (audioList.size() != 1) return false;
146134

147-
return audioList.get(playIndex).isPlaying();
148-
}
135+
public boolean isPlaying() throws Exception {
136+
if (audioList.size() != 1) return false;
149137

138+
return audioList.get(playIndex).isPlaying();
139+
}
150140
}

0 commit comments

Comments
 (0)