Comments (15)
Wish I could help. I've moved on to Xamarin.
from cordova-plugin-media.
The -1 problem is solved in this pull request: #197 by @BuddyLReno
Can you maybe try the version from this branch and see if this maybe also fixes the 0
problem you are having?
My guess would be that for some files the duration just can't be detected. Can you share the URL of such a MP3 file?
from cordova-plugin-media.
This one, does not play and returns 0. But plays fine and give the correct duration if I download it first.
This one plays fine everytime and returns the correct duration. (after a returning couple -1s)
from cordova-plugin-media.
Can you help out building a super simple reproduction app with cordova create
? Just two play buttons, the functionality to show the duration somehow should be enough. Otherwise anyone looking into this has to do that first.
from cordova-plugin-media.
@jb280 also try renaming and reuploading the file. Possible something got corrupted when the file was uploaded? Just a guess. Hard to say what the issue is except something with the file itself since they're being served from the same location.
from cordova-plugin-media.
I downloaded both files and looked at them (and checked with some "check if mp3 is broken" tools I could quickly google), they look just fine tbh.
from cordova-plugin-media.
I have a sample using ionic, will that be helpful to you? It seems to be related to either files ize ( perhaps image size embedded in an MP3 tags?) or network latency. The file I'm having trouble with will play more reliably over Wifi, than cellular. Cellular fails 3 times out of 5 times for me, and I get a 0 duration and no audio playing. But other times it does play. The "play working" sample below seems to play 100% of the time.
home.ts
import` { Component } from '@angular/core';
import {Media, MediaObject} from "@ionic-native/media";
@component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
f1 : MediaObject;
f2 : MediaObject;
d1Duration: number = -5;
d2Duration: number = -5;
d1Cnt : number;
d2Cnt: number;
durationCnt1 : number = 0;
durationCnt2 : number = 0;
constructor( private audioFile: Media) {}
PlayNotworking () {
this.d1Cnt = 0;
this.f1 = this.audioFile.create("https://s3-us-west-2.amazonaws.com/series-stream/Warring+Spiritually/CD+4+-++Warring+Spiritually.mp3")
this.f1.play();
this.getDuration1();
}
Playworking () {
this.d2Cnt = 0;
this.f2 = this.audioFile.create("https://s3-us-west-2.amazonaws.com/series-stream/Fruitful+Repentance/CD+1+-++Fruitful+Repentance.mp3")
this.f2.play();
this.getDuration2();
}
StopNotworking () {
this.f1.stop();
this.f1.release();
this.d1Cnt = 0;
this.d1Duration = -5;
}
Stopworking () {
this.f2.stop();
this.f2.release();
this.d2Cnt = 0;
this.d2Duration = -5;
}
getDuration1()
{
setTimeout(() => {
this.d1Cnt += 1;
if ( this.d1Cnt > 8 ) {
return;
}
this.d1Duration = this.f1.getDuration();
console.log("checkDuration duration = ", this.d1Duration, "d1Cnt = ", this.d1Cnt);
if (this.d1Duration > 0 )
return;
this.getDuration1();
}, 2000);
}
getDuration2()
{
setTimeout(() => {
this.d2Cnt = this.d2Cnt + 1;
if ( this.d2Cnt > 8 ) {
return;
}
this.d2Duration = this.f2.getDuration();
console.log("checkDuration duration = ", this.d2Duration, "d2Cnt = ", this.d2Cnt);
if (this.d2Duration > 0 )
return;
this.getDuration2();
}, 2000);
}
}
home.html
Ionic Blank<button ion-button (click)="Playworking()"> Play Working
<button ion-button (click)="Stopworking()"> Stop/Reset
Duration: {{d2Duration}} Retry: {{d2Cnt}}
<button ion-button (click)="PlayNotworking()"> Play Not Working
<button ion-button (click)="StopNotworking()"> Stop/Reset
Duration: {{d1Duration}} Retry: {{d1Cnt}}
from cordova-plugin-media.
Ionic is fine as well. Please upload the project to Github, so we just have to check it out. Creating a project manually, adding all those files, debugging any build failures etc is a reason not to look into this for any committer.
from cordova-plugin-media.
https://github.com/jb280/mediaDemo
from cordova-plugin-media.
Currently on a Windows machine: Works on Android. Will try iOS later.
from cordova-plugin-media.
I ran 3 sets of 5 tests on a cellular connection. The most I got was 3 working in one set, the worst was 5 not working. I did get a better result over Wifi. I am still using Ionic 3.18.0 CLI ( because of some things in the larger project), and cordova-plugin-media 5.0.2. Might that be an issue?
My workaround for this project was to download the file with cordova-plugin-file-transfer, and then play it, that works 100% of the time with the same audio files.
from cordova-plugin-media.
Ionic CLI has no influence at all at the resulting app. It is just a local tool.
And cordova-plugin-media 5.0.2 is the current version.
But the information that the bug depends on the connection type is interesting. Will take this into account when further testing this.
from cordova-plugin-media.
Did you have any luck reproducing this on iOS? I still get 2 failures ( getDuration() returns 0) 2 out of 5 time on cellular ( AT&T 3-4bars). The audio never plays. My working of download the whole filed locally first does work, but I don't like the delay of having to download the whole file before starting the audio.
from cordova-plugin-media.
I now get this in Xcode, when it fails in my real app.
35: CheckRPCError: AudioSessionSetActive_Priv returned server mach error 0x10000003!
Unable to play audio: (null)
getDuration() returns NaN.
It is not on lock-screen, there is no other audio playing. If I turn on WiFi while it is retying the same file it will load and play.
My guess is for that some larger files on a slower link, it might sometimes read zero bytes, and assume it was the EOF, or network error?
from cordova-plugin-media.
Any news on this issue? I download the demo provided by @BuddyLReno on #197, changed the mediaUrl to this and the media duration using the update callback is -1 too.
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
- 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.