Comments (4)
Couple of details for anyone trying to get looping to work:
On iOS
It works great IF you use a local resource media file or download the file and reference it as a cdvfile:// before playing. It will not work for an internet url. That will cause this plugin to use AVPlayer which doesn't support looping out of the box (you can kind of rig it in javascript, but I wouldn't trust it's stability).
To get a local file to loop forever (until stop is called or the app is closed) set {numberOfLoops: -1} on play()
On Android
numberOfLoops does nothing.
I tried many javascript ideas to get around this. You can definitely rig it, but you will get the occasional skip and it's not very reliable. It tried fading one out while fading in the next with setVolume(), this works but you can tell what's going on (not seamless) and I don't think it would be a solid solution.
I tried rewriting the native part of this plugin to reuse 2 MediaPlayers and specify the next via setNextMediaPlayer(). This worked, but chopped off the very end of the audio file before looping, not seamless.
After a lot of trial and error I would definitely suggest exoplayer2 for android gapless looping. I hesitated to add it, but it only ads 2mb to your apk and is very feature rich to use it again elsewhere. It's able to loop files without downloading them first and it can also read metadata in mp3s if it is set to get them to loop correctly (which is often a problem in with looping mp3s). Only downside, exoplayer doesn't work for iOS but this plugin, a local file, and play({numberOfLoops:-1}) does.
Creating audio files that don't have audible pops is another thing you'll have to consider.
Happy loopin'!
from cordova-plugin-media.
//to listen to plugin stop events
fileBg.onStatusUpdate.subscribe(status => {
if (status == 4) {
fileBg.play();
}
});
from cordova-plugin-media.
https://software.intel.com/es-es/forums/intel-xdk/topic/562553
from cordova-plugin-media.
Couple of details for anyone trying to get looping to work:
On iOS
It works great IF you use a local resource media file or download the file and reference it as a cdvfile:// before playing. It will not work for an internet url. That will cause this plugin to use AVPlayer which doesn't support looping out of the box (you can kind of rig it in javascript, but I wouldn't trust it's stability).To get a local file to loop forever (until stop is called or the app is closed) set {numberOfLoops: -1} on play()
On Android
numberOfLoops does nothing.I tried many javascript ideas to get around this. You can definitely rig it, but you will get the occasional skip and it's not very reliable. It tried fading one out while fading in the next with setVolume(), this works but you can tell what's going on (not seamless) and I don't think it would be a solid solution.
I tried rewriting the native part of this plugin to reuse 2 MediaPlayers and specify the next via setNextMediaPlayer(). This worked, but chopped off the very end of the audio file before looping, not seamless.
After a lot of trial and error I would definitely suggest exoplayer2 for android gapless looping. I hesitated to add it, but it only ads 2mb to your apk and is very feature rich to use it again elsewhere. It's able to loop files without downloading them first and it can also read metadata in mp3s if it is set to get them to loop correctly (which is often a problem in with looping mp3s). Only downside, exoplayer doesn't work for iOS but this plugin, a local file, and play({numberOfLoops:-1}) does.
Creating audio files that don't have audible pops is another thing you'll have to consider.
Happy loopin'!
I have been using the Audio WEB API untill now.. It has bugs when going into the background etc.. It has been very performant to loop and also for polyphonic audio. But I need to get rid of the bugs it us causing. SO i switched to Capacitor instead of cordova and now I need to find a way to reference the assets directly but I can't seem to get the correct path..
[UPDATE] Okay I figured out how to load the files .. but man... the looping is terrible... gaps all over the place and no synchronization.. Also when I try to play multiple sounds at once.. It is a disaster ... (I am making a music sample app with a sequencer) -> when I use web audio API it works flawllesly.. only the sond is gone there when the app is sent to background.. which is a totally different problem but still ..
from cordova-plugin-media.
Related Issues (20)
- In Android include webView cookies for streaming in setDataSource()
- Do you support Electron? HOT 2
- Detection of missing microphone access permission HOT 2
- Android 12 (api 31-32) - audio not playing error 1 HOT 8
- Get frame(s) from Video stream HOT 1
- Document preference value "KeepAVAudioSessionAlwaysActive" used in config.xml
- Android: play & seekTo => error (-38, 0), start called in state 4
- Audio stream starts delay
- Error on install "cordova-plugin-media" - Cannot find plugin.xml HOT 11
- ios only: sound not playing when app is in background and some other app has sound on
- Can't record audio on app targeting Android 13 due to plugin requesting WRITE_EXTERNAL_STORAGE permission (which always fails) HOT 10
- Exception when Play Sound Android API v33 HOT 6
- Can't play in background
- i can't play audio in cordova 12 HOT 14
- i can't play audio
- I want to use a cordova plugin in a capacitor project. But import doesn't work. And I cannot find instructions how to use it. I installed npm i cordova-plugin-dbmeter old code would use import { DBMeter } from 'cordova-plugin-dbmeter'; But that gives an error. I don't know what to do to make this part work: constructor(private dbMeter: DBMeter, ... And I find different options: create capacitor plugin, create a wrapper, or call directly. I cannot find in which cases you should do what. But whatever I try, I cannot get it to work. Can there be more examples for using cordova-plugins in capacitor-code? HOT 1
- Audio from other app is not returning to continue playing after sound from plugin finish playing HOT 5
- Android 14 Won't Play MP3 files HOT 2
- Failed to start recording using AVAudioRecorder: (null) code:1 HOT 1
- Anomalous Permission Usage (for RECORD_AUDIO permission)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-plugin-media.