@mcfarljw/capacitor-audio 1.1.2 → 2.0.0
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.
- package/McfarljwCapacitorAudio.podspec +1 -1
- package/android/build.gradle +9 -9
- package/android/src/main/java/com/mcfarljw/capacitor/audio/CapacitorAudio.java +39 -40
- package/android/src/main/java/com/mcfarljw/capacitor/audio/CapacitorAudioPlugin.java +0 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorAudio.swift +18 -18
- package/ios/Plugin/CapacitorAudioPlugin.swift +8 -8
- package/package.json +18 -18
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
13
|
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target = '
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
16
|
s.swift_version = '5.1'
|
|
17
17
|
end
|
package/android/build.gradle
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
@@ -11,7 +11,7 @@ buildscript {
|
|
|
11
11
|
mavenCentral()
|
|
12
12
|
}
|
|
13
13
|
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:8.2
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -19,10 +19,10 @@ apply plugin: 'com.android.library'
|
|
|
19
19
|
|
|
20
20
|
android {
|
|
21
21
|
namespace "com.mcfarljw.capacitor.audio"
|
|
22
|
-
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion :
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
23
|
defaultConfig {
|
|
24
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion :
|
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
26
|
versionCode 1
|
|
27
27
|
versionName "1.0"
|
|
28
28
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -37,8 +37,8 @@ android {
|
|
|
37
37
|
abortOnError false
|
|
38
38
|
}
|
|
39
39
|
compileOptions {
|
|
40
|
-
sourceCompatibility JavaVersion.
|
|
41
|
-
targetCompatibility JavaVersion.
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -4,24 +4,23 @@ import android.content.Context;
|
|
|
4
4
|
import android.media.SoundPool;
|
|
5
5
|
import android.net.Uri;
|
|
6
6
|
import android.util.Log;
|
|
7
|
-
|
|
7
|
+
import com.getcapacitor.Bridge;
|
|
8
8
|
import java.io.File;
|
|
9
9
|
import java.io.IOException;
|
|
10
10
|
import java.util.HashMap;
|
|
11
11
|
import java.util.Map;
|
|
12
12
|
|
|
13
|
-
import com.getcapacitor.Bridge;
|
|
14
|
-
|
|
15
13
|
public class CapacitorAudio {
|
|
14
|
+
|
|
16
15
|
private static final String PLUGIN_NAME = "CapacitorAudioPlugin";
|
|
17
16
|
|
|
18
17
|
private SoundPool mSoundPool;
|
|
19
18
|
|
|
20
|
-
final
|
|
21
|
-
final
|
|
22
|
-
final
|
|
23
|
-
final
|
|
24
|
-
final
|
|
19
|
+
private final HashMap<Integer, HashMap<String, Integer>> audioTracks = new HashMap<>();
|
|
20
|
+
private final float mSoundRate = 1.0f;
|
|
21
|
+
private final float mSoundVolume = 1.0f;
|
|
22
|
+
private final Bridge bridge;
|
|
23
|
+
private final Context context;
|
|
25
24
|
|
|
26
25
|
public CapacitorAudio(Context context, Bridge bridge) {
|
|
27
26
|
this.bridge = bridge;
|
|
@@ -30,7 +29,7 @@ public class CapacitorAudio {
|
|
|
30
29
|
this.load();
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
public void load
|
|
32
|
+
public void load() {
|
|
34
33
|
if (mSoundPool != null) {
|
|
35
34
|
mSoundPool.release();
|
|
36
35
|
}
|
|
@@ -48,44 +47,44 @@ public class CapacitorAudio {
|
|
|
48
47
|
final String absolutePath = context.getFilesDir().getAbsolutePath() + "/" + trimmedPath;
|
|
49
48
|
final String parsedPath = Uri.parse(absolutePath).getPath();
|
|
50
49
|
|
|
51
|
-
this.bridge.getActivity()
|
|
52
|
-
|
|
53
|
-
audioTracks.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
try {
|
|
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());
|
|
50
|
+
this.bridge.getActivity()
|
|
51
|
+
.runOnUiThread(() -> {
|
|
52
|
+
if (!audioTracks.containsKey(track)) {
|
|
53
|
+
audioTracks.put(track, new HashMap<>());
|
|
54
|
+
}
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
audioTracks.get(track).
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Log.i(PLUGIN_NAME, "public file not found: " + error.getMessage());
|
|
74
|
-
}
|
|
60
|
+
final File file = new File(parsedPath);
|
|
61
|
+
int soundId;
|
|
62
|
+
|
|
63
|
+
Log.d(PLUGIN_NAME, "playing file: " + file.getAbsolutePath());
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
soundId = mSoundPool.load(
|
|
65
|
+
if (file.exists()) {
|
|
66
|
+
soundId = mSoundPool.load(file.getPath(), 1);
|
|
78
67
|
audioTracks.get(track).put(trimmedPath, soundId);
|
|
79
|
-
}
|
|
80
|
-
|
|
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
|
}
|
|
84
|
-
}
|
|
85
|
-
Log.i(PLUGIN_NAME, "Unable to play audio!");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
});
|
|
87
|
+
});
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
public void stop(int track) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CapacitorAudioPlugin {\n play(options: { path: string
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CapacitorAudioPlugin {\n play(options: { path: string; track: number }): Promise<void>;\n stop(options: { track: number }): Promise<void>;\n stopAll(): Promise<void>;\n}\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
2
|
const CapacitorAudio = registerPlugin('CapacitorAudio', {
|
|
3
|
-
web: () => import('./web').then(m => new m.CapacitorAudioWeb()),
|
|
3
|
+
web: () => import('./web').then((m) => new m.CapacitorAudioWeb()),
|
|
4
4
|
});
|
|
5
5
|
export * from './definitions';
|
|
6
6
|
export { CapacitorAudio };
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAClE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapacitorAudioPlugin } from './definitions';\n\nconst CapacitorAudio = registerPlugin<CapacitorAudioPlugin>('CapacitorAudio', {\n web: () => import('./web').then((m) => new m.CapacitorAudioWeb()),\n});\n\nexport * from './definitions';\nexport { CapacitorAudio };\n"]}
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,KAAK,CAAC,IAAI,CAAC,OAAwC;QACjD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CapacitorAudioPlugin } from './definitions';\n\nexport class CapacitorAudioWeb extends WebPlugin implements CapacitorAudioPlugin {\n async play(options: { path: string; track: number }): Promise<void> {\n console.log('play', options);\n }\n async stop(options: { track: number }): Promise<void> {\n console.log('stop', options);\n }\n async stopAll(): Promise<void> {\n console.log('stopAll');\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@capacitor/core');
|
|
6
4
|
|
|
7
5
|
const CapacitorAudio = core.registerPlugin('CapacitorAudio', {
|
|
8
|
-
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorAudioWeb()),
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorAudioWeb()),
|
|
9
7
|
});
|
|
10
8
|
|
|
11
9
|
class CapacitorAudioWeb extends core.WebPlugin {
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudio = registerPlugin('CapacitorAudio', {\n web: () => import('./web').then(m => new m.CapacitorAudioWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudio };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorAudioWeb extends WebPlugin {\n async play(options) {\n console.log('play', options);\n }\n async stop(options) {\n console.log('stop', options);\n }\n async stopAll() {\n console.log('stopAll');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudio = registerPlugin('CapacitorAudio', {\n web: () => import('./web').then((m) => new m.CapacitorAudioWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudio };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorAudioWeb extends WebPlugin {\n async play(options) {\n console.log('play', options);\n }\n async stop(options) {\n console.log('stop', options);\n }\n async stopAll() {\n console.log('stopAll');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;AACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACrE,CAAC;;ACFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;AACjD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC;AACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC;AACA,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AAC9B;AACA;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -2,7 +2,7 @@ var capacitorCapacitorAudio = (function (exports, core) {
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const CapacitorAudio = core.registerPlugin('CapacitorAudio', {
|
|
5
|
-
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorAudioWeb()),
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorAudioWeb()),
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
class CapacitorAudioWeb extends core.WebPlugin {
|
|
@@ -24,8 +24,6 @@ var capacitorCapacitorAudio = (function (exports, core) {
|
|
|
24
24
|
|
|
25
25
|
exports.CapacitorAudio = CapacitorAudio;
|
|
26
26
|
|
|
27
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
28
|
-
|
|
29
27
|
return exports;
|
|
30
28
|
|
|
31
29
|
})({}, capacitorExports);
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudio = registerPlugin('CapacitorAudio', {\n web: () => import('./web').then(m => new m.CapacitorAudioWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudio };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorAudioWeb extends WebPlugin {\n async play(options) {\n console.log('play', options);\n }\n async stop(options) {\n console.log('stop', options);\n }\n async stopAll() {\n console.log('stopAll');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;IACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorAudio = registerPlugin('CapacitorAudio', {\n web: () => import('./web').then((m) => new m.CapacitorAudioWeb()),\n});\nexport * from './definitions';\nexport { CapacitorAudio };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorAudioWeb extends WebPlugin {\n async play(options) {\n console.log('play', options);\n }\n async stop(options) {\n console.log('stop', options);\n }\n async stopAll() {\n console.log('stopAll');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;IACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACrE,CAAC;;ICFM,MAAM,iBAAiB,SAASC,cAAS,CAAC;IACjD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC;IACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC;IACA,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAC9B;IACA;;;;;;;;;;;;;;;"}
|
|
@@ -4,41 +4,41 @@ import Foundation
|
|
|
4
4
|
@objc public class CapacitorAudio: NSObject, AVAudioPlayerDelegate {
|
|
5
5
|
private let queue = DispatchQueue(label: "com.capacitor.audio", qos: .userInitiated)
|
|
6
6
|
private var players: [Int: AVAudioPlayer] = [:]
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
var documentDirectory: String!
|
|
9
9
|
var wwwDirectory: String!
|
|
10
10
|
var publicDirectory: String!
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
@objc public func load() {
|
|
13
13
|
let searchPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
self.documentDirectory = searchPaths[0]
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
if let resourcePath = Bundle.main.resourcePath {
|
|
18
18
|
self.wwwDirectory = resourcePath + "/www"
|
|
19
19
|
self.publicDirectory = resourcePath + "/public"
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
do {
|
|
23
23
|
try AVAudioSession.sharedInstance().setCategory(.playback, options: .mixWithOthers)
|
|
24
24
|
} catch {
|
|
25
25
|
print("Unable to set audio session category: \(error)")
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
@objc public func play(_ path: String, _ track: Int) {
|
|
30
30
|
let trimmedPath = path.trimmingCharacters(in: .whitespaces)
|
|
31
31
|
.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
let documentPath = self.documentDirectory! + "/" + trimmedPath
|
|
34
34
|
let wwwPath = self.wwwDirectory! + "/" + trimmedPath
|
|
35
35
|
let publicPath = self.publicDirectory! + "/" + trimmedPath
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
queue.async { [weak self] in
|
|
38
38
|
guard let self = self else { return }
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
var audioUrl: URL?
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
if FileManager.default.fileExists(atPath: publicPath) {
|
|
43
43
|
audioUrl = URL(fileURLWithPath: publicPath)
|
|
44
44
|
} else if FileManager.default.fileExists(atPath: wwwPath) {
|
|
@@ -46,13 +46,13 @@ import Foundation
|
|
|
46
46
|
} else if FileManager.default.fileExists(atPath: documentPath) {
|
|
47
47
|
audioUrl = URL(fileURLWithPath: documentPath)
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
guard let audioUrl = audioUrl else { return }
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
do {
|
|
53
53
|
let player = try AVAudioPlayer(contentsOf: audioUrl)
|
|
54
54
|
|
|
55
|
-
player.delegate = self
|
|
55
|
+
player.delegate = self
|
|
56
56
|
self.players[track] = player
|
|
57
57
|
|
|
58
58
|
player.play()
|
|
@@ -61,14 +61,14 @@ import Foundation
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
@objc public func stop(_ track: Int) {
|
|
66
66
|
queue.async { [weak self] in
|
|
67
67
|
self?.players[track]?.stop()
|
|
68
68
|
self?.players.removeValue(forKey: track)
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
@objc public func stopAll() {
|
|
73
73
|
queue.async { [weak self] in
|
|
74
74
|
self?.players.values.forEach { player in
|
|
@@ -77,14 +77,14 @@ import Foundation
|
|
|
77
77
|
self?.players.removeAll()
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
|
|
82
82
|
queue.async { [weak self] in
|
|
83
83
|
guard let self = self else { return }
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
if let index = self.players.firstIndex(where: { $0.value === player }) {
|
|
86
86
|
self.players.removeValue(forKey: self.players[index].key)
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
}
|
|
90
|
+
}
|
|
@@ -8,7 +8,7 @@ import Capacitor
|
|
|
8
8
|
@objc(CapacitorAudioPlugin)
|
|
9
9
|
public class CapacitorAudioPlugin: CAPPlugin {
|
|
10
10
|
private let implementation = CapacitorAudio()
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
override public func load() {
|
|
13
13
|
implementation.load()
|
|
14
14
|
}
|
|
@@ -16,23 +16,23 @@ public class CapacitorAudioPlugin: CAPPlugin {
|
|
|
16
16
|
@objc func play(_ call: CAPPluginCall) {
|
|
17
17
|
let path = call.getString("path") ?? ""
|
|
18
18
|
let track = call.getInt("track", 0)
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
implementation.play(path, track)
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
call.resolve()
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
@objc func stop(_ call: CAPPluginCall) {
|
|
26
26
|
let track = call.getInt("track", 0)
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
implementation.stop(track)
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
call.resolve()
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
@objc func stopAll(_ call: CAPPluginCall) {
|
|
34
34
|
implementation.stopAll()
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
call.resolve()
|
|
37
37
|
}
|
|
38
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcfarljw/capacitor-audio",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A native audio plugin for Ionic Capacitor.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -36,30 +36,30 @@
|
|
|
36
36
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
37
37
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
38
38
|
"eslint": "eslint . --ext ts",
|
|
39
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
39
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
40
40
|
"swiftlint": "node-swiftlint",
|
|
41
41
|
"docgen": "docgen --api CapacitorAudioPlugin --output-readme README.md --output-json dist/docs.json",
|
|
42
|
-
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.
|
|
42
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
43
43
|
"clean": "rimraf ./dist",
|
|
44
44
|
"watch": "tsc --watch",
|
|
45
45
|
"prepublishOnly": "npm run build"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@capacitor/android": "^
|
|
49
|
-
"@capacitor/cli": "^
|
|
50
|
-
"@capacitor/core": "^
|
|
51
|
-
"@capacitor/docgen": "^0.0
|
|
52
|
-
"@capacitor/ios": "^
|
|
53
|
-
"@ionic/eslint-config": "^0.
|
|
54
|
-
"@ionic/prettier-config": "^
|
|
55
|
-
"@ionic/swiftlint-config": "^
|
|
56
|
-
"eslint": "^
|
|
57
|
-
"prettier": "
|
|
58
|
-
"prettier-plugin-java": "
|
|
59
|
-
"rimraf": "^
|
|
60
|
-
"rollup": "^
|
|
61
|
-
"swiftlint": "^
|
|
62
|
-
"typescript": "
|
|
48
|
+
"@capacitor/android": "^7.0.0",
|
|
49
|
+
"@capacitor/cli": "^7.0.0",
|
|
50
|
+
"@capacitor/core": "^7.0.0",
|
|
51
|
+
"@capacitor/docgen": "^0.3.0",
|
|
52
|
+
"@capacitor/ios": "^7.0.0",
|
|
53
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
55
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"prettier": "^3.4.2",
|
|
58
|
+
"prettier-plugin-java": "^2.6.6",
|
|
59
|
+
"rimraf": "^6.0.0",
|
|
60
|
+
"rollup": "^4.30.0",
|
|
61
|
+
"swiftlint": "^2.0.0",
|
|
62
|
+
"typescript": "^4.1.5"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@capacitor/core": "^6.0.0"
|