cordova-plugin-media
cordova-plugin-media copied to clipboard
Getting status on file loaded
Im building an streaming app with ionic and capacitor and i need some way to detect that the stream url did in fact load
here's an example:
this.media.create(urlLiveBroadcast); this.media.play() it doesnt work because the urlLiveBroadcast takes like 5 seconds to load, and there is no status event to handle that
if i create the media within the app initialization it keeps using the network before you tap de "play" button
how should i proceed?
Hello @capiztrr, I think we have the same issue.
When we are on a fast network (i. e. WiFi), the stream url loads almost immediately and the play()
method works as expected. However, when we are on 3G/4G, the stream sometimes does not start the play. The plugin still reports Status = 2
. Did you find a good solution?
One possibility is to use a timeout function to wait for a few seconds before playing. But this is also a long shot because it will still not work in some cases, and in other cases you wait longer than necessary.
i didnt find any solution yet.
Yes, you can hardcode like 10 seconds before calling the play method, but its a really weak solution
i didnt find any solution yet.
Yes, you can hardcode like 10 seconds before calling the play method, but its a really weak solution
Indeed. Also I found that Android starts playing immediately for around 5 seconds and then starts to buffering for 5 seconds. Really confusing for the listener because it is unclear whether the stream is actually buffering or broken.
I never got it working on android. I had to use HTML Audio for android
I'm using ionic
and cordova
. I have no issue with version 5.0.3
and Android
, but I get the same issue on iOS
:
- if I create the
Media
and callplay
right after, I do seeMedia.MEDIA_RUNNING
status, but I don't hear anything - if I put a 5s timeout between the 2 calls, it works
I reverted back to version 4.0.0
only on iOS
to fix the issue.
I'm streaming audio from the Internet using HTTPS.
I solved this issue in the following way: I added a new method
async start(url) {
this.player = this.media.create(url);
await this.startPlay();
}
startPlay() {
return new Promise((resolve, reject) => {
let playInterval = setInterval(() => {
this.player.play({ numberOfLoops: 1, playAudioWhenScreenIsLocked: true });
this.player.getCurrentPosition().then((position) => {
if (position > 0) {
resolve(position);
clearInterval(playInterval);
}
});
}, 2000);
})
}
I believe this is the same problem as https://github.com/apache/cordova-plugin-media/issues/256. I solved it in my fork by setting automaticallyWaitsToMinimizeStalling
to YES
(tested on iPad and iPhone with iOS 15, HTTP static MP3 ad live streams, without any adverse effect).