I’ve been using the ionic native - native audio plugin to preload and play short audio files in my app, but the cordova-plugin that it’s based on is unmaintained and I’m hoping to move away towards html5 audio.
I don’t need background audio or controls, since the audio in my app is short 1-3 second clips. Is there any easy way to just play a short audio track on a button tap?
var audio1 = new Audio("assets/aud/audio1.mp3");
var audio2 = new Audio("assets/aud/audio2.mp3");
var audio3 = new Audio("assets/aud/audio3.mp3");
play1() {
audio1.play();
}
play2() {
audio2.play();
}
play3() {
audio3.play();
}
Is this anything close to a good solution? Anything that I need to look out for with respect to unloading the files from memory? Sorry if this is a dumb question but the documentation for html5 audio that I’ve found is all aimed at the web and I can’t find any examples for ionic specific implementations…
That’s the plugin that I currently use and that I’m trying to move away from. I have a few thousand android users and get around 10 error reports per month from the underlying Cordova plugin. It’s a fairly small number, a fraction of a percent of all sessions, but I’d still prefer 0 crashes and to move to web technologies so that I might be able to release a PWA in the future.
Floatinghotpot (maintainer of the Cordova plugin) hasn’t merged a PR for months and doesn’t seem interested in working any further in Cordova native audio. It still works now but I’d prefer to switch early before a breaking change comes along with Android P or iOS 12 that forces me to adapt quickly.
Awesome thanks for the sample code and the tips! I’m planning on dropping Ionic’s routing/lifecycle events and moving to Angular router with Ionic 4 once it moves to beta.
I’ll switch to html5 audio at the same time that I do the framework update and hopefully that will put me in a pretty solid position moving forward without too many breaking changes. Fingers crossed!
Yes, cordova & native wrapper would totally make it work.
This SDK package is perfect. It has the best features for any audio playback… and it’s not that difficult to configure. It works with simple commands like Play(), Stop(), etc.
So I imagine, it’s possible for Ionic team to create a plugin for this?
and it’s free. I think this one beats cordova audio plugins, html5 audio easily. Cordova audio plugin is a toy when compared to Superpowered SDK.
I personally wished Capaciitor will ship with Superpowered audio engine built-in…
I hadn’t heard of superpowered before but it looks like a cool project. It’s definitely not free and open source though, it has both proprietary code and a propreitary license that they can change at any point.
I think that the ionic team is wise to stick with free software with permissive licenses such as MIT, even if there are some compromises that need to be made to meet this criteria.
It’s free until you get 500,000 installs: Subject to all other terms below, if Licensee uses the SUPERPOWERED AUDIO SDK in an Embedded Application or Pre-Bundled or Pre-Installed or Platform Application, or has an application with over 500,000 installs, Licensee must secure a paid license from Superpowered Inc
That’s right. Ionic team will be charged if they they publish Superpowered as a part of Capacitor… I didn’t understand their licensing fee policy. The only solution for us is anonymous guy making a cordova plugin for Superpowered.
A guy attempted this for React Native and was partially successful:
No, it is free for the most users… if you become successful with their SDK, you can buy their paid license. I would love to do that. It’s like Firebase. Firebase gives you 10GB free every month so you can try until you become successful. If you don’t make anything from it, you’re not required to pay anything. Once you get high traffic, you can start pay per GB download.
They quoted 500,000 installs so I can imagine only the most successful apps will be required to buy paid license. Some great audio apps get 30,000 - 50,000 downloads.
The Superpowered Audio SDK offers free and paid licenses. Most apps qualify for a free license.
This is their free license description:
Distributed in a public application store system
The total number of installations is fewer than 500,000
Yes I understand that it costs $0 for most users, but like I said in my previous post and as explained in the Wikipedia article “Free software is a matter of liberty, not price”
Software can have a price of $0 and still not be free, since the licensing is restrictive and doesn’t provide freedom to the developer or end user
Hello,
I’hv tried something like:
let audio = new Audio();
audio.src = “assets/myfile.wav”;
audio.play();
This is working perfectly in android. But not work in ios.
Please give me some ideas how can i play an audio in ios whrn any toast message is showing up.