capacitor-community / capacitor-community/native-audio

trying to get audio file size, on promise return, context (this) is lost

Open
#75 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
154
Forks
78
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
ios16, xcode 14, ionic vue 6, capacitor 4.
tried with .then() as well.
```
async doLoad() {
await NativeAudio.preload({
assetId: "ping",
assetPath: "sonar-ping-95840.mp3",
audioChannelNum: 1,
isUrl: false
})
this.LogIt("ping getting audio duration")
let result= await NativeAudio.getDuration({
assetId: 'ping'
})
let r = result.duration * 1000
this.LogIt("in ms =" + r)
this.setms(r)
```
see output
```
⚡️ To Native -> NativeAudio getDuration 58430391
⚡️ [log] - 1676737401023 ping getting audio duration
⚡️ TO JS {"duration":1.0187755102040816}
⚡️ [log] - 1676737401025 in ms =1018.7755102040817
```
then
⚡️ TO JS undefined
⚡️ TO JS undefined
```
tried calling from IonicViewDidEnter()
and created()
tried using self instead of this

I am trying to save the ms elapsed so I can wait til the play finishes, so i don't keep chopping it off while playing.
not clear if play waits to return until finished.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS] Mac OS
- Browser [e.g. chrome, safari] this is native mode app
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6] iphone 12
- OS: [e.g. iOS8.1] ios 16.2
- Browser [e.g. stock browser, safari]???
- Version [e.g. 22]???

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.