@mcfarljw/capacitor-audio 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'CapacitorAudio'
6
+ s.name = 'McfarljwCapacitorAudio'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.license = package['license']
@@ -44,43 +44,47 @@ public class CapacitorAudio {
44
44
 
45
45
  public void play(String path, int track) {
46
46
  final Context context = this.context;
47
- final String trimmedPath = path.replaceAll("^/+", "");
47
+ final String trimmedPath = path.trim().replaceAll("^/+", "");
48
48
  final String absolutePath = context.getFilesDir().getAbsolutePath() + "/files/" + trimmedPath;
49
49
  final String parsedPath = Uri.parse(absolutePath).getPath();
50
50
 
51
-
52
- if (!audioTracks.containsKey(track)) {
53
- audioTracks.put(track, new HashMap<>());
54
- }
55
-
56
51
  this.bridge.getActivity().runOnUiThread(() -> {
57
- if (audioTracks.get(track).containsKey(trimmedPath)) {
58
- mSoundPool.play(audioTracks.get(track).get(trimmedPath), mSoundVolume, mSoundVolume, 1, 0, mSoundRate);
59
- } else {
60
- final File file = new File(parsedPath);
61
- int soundId;
62
-
63
- Log.d(PLUGIN_NAME, "playing file: " + file.getAbsolutePath());
52
+ if (!audioTracks.containsKey(track)) {
53
+ audioTracks.put(track, new HashMap<>());
54
+ }
64
55
 
65
- if (file.exists()) {
66
- soundId = mSoundPool.load(file.getPath(), 1);
67
- audioTracks.get(track).put(trimmedPath, soundId);
56
+ try {
57
+ if (audioTracks.get(track).containsKey(trimmedPath)) {
58
+ mSoundPool.play(audioTracks.get(track).get(trimmedPath), mSoundVolume, mSoundVolume, 1, 0, mSoundRate);
68
59
  } else {
69
- try {
70
- soundId = mSoundPool.load(context.getAssets().openFd("public/" + trimmedPath), 1);
71
- audioTracks.get(track).put(trimmedPath, soundId);
72
- } catch (IOException error) {
73
- Log.i(PLUGIN_NAME, "public file not found: " + error.getMessage());
74
- }
60
+ final File file = new File(parsedPath);
61
+ int soundId;
75
62
 
76
- try {
77
- soundId = mSoundPool.load(context.getAssets().openFd("www/" + trimmedPath), 1);
63
+ Log.d(PLUGIN_NAME, "playing file: " + file.getAbsolutePath());
64
+
65
+ if (file.exists()) {
66
+ soundId = mSoundPool.load(file.getPath(), 1);
78
67
  audioTracks.get(track).put(trimmedPath, soundId);
79
- } catch (IOException error) {
80
- Log.d(PLUGIN_NAME, "www file not found: " + error.getMessage());
68
+ } else {
69
+ try {
70
+ soundId = mSoundPool.load(context.getAssets().openFd("public/" + trimmedPath), 1);
71
+ audioTracks.get(track).put(trimmedPath, soundId);
72
+ } catch (IOException error) {
73
+ Log.i(PLUGIN_NAME, "public file not found: " + error.getMessage());
74
+ }
75
+
76
+ try {
77
+ soundId = mSoundPool.load(context.getAssets().openFd("www/" + trimmedPath), 1);
78
+ audioTracks.get(track).put(trimmedPath, soundId);
79
+ } catch (IOException error) {
80
+ Log.d(PLUGIN_NAME, "www file not found: " + error.getMessage());
81
+ }
81
82
  }
82
83
  }
84
+ } catch (NullPointerException error) {
85
+ Log.i(PLUGIN_NAME, "Unable to play audio!");
83
86
  }
87
+
84
88
  });
85
89
  }
86
90
 
@@ -1,5 +1,7 @@
1
1
  package com.mcfarljw.capacitor.audio;
2
2
 
3
+ import androidx.annotation.NonNull;
4
+
3
5
  import com.getcapacitor.Plugin;
4
6
  import com.getcapacitor.PluginCall;
5
7
  import com.getcapacitor.PluginMethod;
@@ -20,7 +22,9 @@ public class CapacitorAudioPlugin extends Plugin {
20
22
  String path = call.getString("path");
21
23
  int track = call.getInt("track", 0);
22
24
 
23
- implementation.play(path, track);
25
+ if (path != null) {
26
+ implementation.play(path, track);
27
+ }
24
28
 
25
29
  call.resolve();
26
30
  }
@@ -27,7 +27,7 @@ import Foundation
27
27
  }
28
28
 
29
29
  @objc public func play(_ path: String, _ track: Int) -> Void {
30
- let trimmedPath = path.trimmingCharacters(in: .whitespaces)
30
+ let trimmedPath = path.trimmingCharacters(in: .whitespaces).trimmingCharacters(in: CharacterSet(charactersIn: "/"))
31
31
  let documentPath = "\(self.documentDirectory!)\(trimmedPath)"
32
32
  let wwwPath = "\(self.wwwDirectory!)\(trimmedPath)"
33
33
  let publicPath = "\(self.publicDirectory!)\(trimmedPath)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcfarljw/capacitor-audio",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A native audio plugin for Ionic Capacitor.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -11,7 +11,7 @@
11
11
  "android/build.gradle",
12
12
  "dist/",
13
13
  "ios/Plugin/",
14
- "CapacitorAudio.podspec"
14
+ "McfarljwCapacitorAudio.podspec"
15
15
  ],
16
16
  "author": "Joshua McFarland <mcfarljw@gmail.com>",
17
17
  "license": "MIT",