@capgo/native-audio 6.4.21 → 6.4.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,7 @@ public class AudioAsset {
13
13
  private int playIndex = 0;
14
14
  private final String assetId;
15
15
  protected final NativeAudio owner;
16
+ protected AudioCompletionListener completionListener;
16
17
 
17
18
  AudioAsset(
18
19
  NativeAudio owner,
@@ -167,4 +168,14 @@ public class AudioAsset {
167
168
 
168
169
  return audioList.get(playIndex).isPlaying();
169
170
  }
171
+
172
+ public void setCompletionListener(AudioCompletionListener listener) {
173
+ this.completionListener = listener;
174
+ }
175
+
176
+ protected void notifyCompletion() {
177
+ if (completionListener != null) {
178
+ completionListener.onCompletion(this.assetId);
179
+ }
180
+ }
170
181
  }
@@ -0,0 +1,5 @@
1
+ package ee.forgr.audio;
2
+
3
+ public interface AudioCompletionListener {
4
+ void onCompletion(String assetId);
5
+ }
@@ -118,7 +118,7 @@ public class AudioDispatcher
118
118
  this.stop();
119
119
 
120
120
  if (this.owner != null) {
121
- this.owner.dispatchComplete();
121
+ this.owner.notifyCompletion();
122
122
  }
123
123
  }
124
124
  } catch (Exception ex) {
@@ -504,6 +504,7 @@ public class NativeAudio
504
504
  audioChannelNum,
505
505
  volume
506
506
  );
507
+ remoteAudioAsset.setCompletionListener(this::dispatchComplete);
507
508
  audioAssetList.put(audioId, remoteAudioAsset);
508
509
  } else if (
509
510
  uri.getScheme() != null && uri.getScheme().equals("file")
@@ -535,6 +536,7 @@ public class NativeAudio
535
536
  audioChannelNum,
536
537
  volume
537
538
  );
539
+ asset.setCompletionListener(this::dispatchComplete);
538
540
  audioAssetList.put(audioId, asset);
539
541
  } else {
540
542
  throw new IllegalArgumentException(
@@ -45,6 +45,9 @@ public class RemoteAudioAsset extends AudioAsset {
45
45
  isPrepared = true;
46
46
  Log.d(TAG, "MediaPlayer prepared for " + uri.toString());
47
47
  });
48
+ mediaPlayer.setOnCompletionListener(mp -> {
49
+ notifyCompletion();
50
+ });
48
51
  mediaPlayer.setOnErrorListener((mp, what, extra) -> {
49
52
  Log.e(TAG, "MediaPlayer error: " + what + ", " + extra);
50
53
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-audio",
3
- "version": "6.4.21",
3
+ "version": "6.4.22",
4
4
  "description": "A native plugin for native audio engine",
5
5
  "main": "dist/plugin.js",
6
6
  "module": "dist/esm/index.js",