Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot preload sound files #294

Open
yunyun27 opened this issue Sep 28, 2020 · 9 comments
Open

Cannot preload sound files #294

yunyun27 opened this issue Sep 28, 2020 · 9 comments

Comments

@yunyun27
Copy link

With media plugin version 1.0.1, you can preload sound files, and play them without any problem.
With the latest media plugin, if you preload multiple sound files, only the last one will be played.

For example:
var a = new Media(file1);
var b = new Media(file2);
a.play(); // works in v.1.0.1 but not the latest version

I'd been using 1.0.1 to bypass the issue but it seems no longer possible with new ios build requirements.

Preloading is quite important for me. Could someone please help? Thank you!

@timbru31
Copy link
Member

It would really help us, if you can identify the version which "broke"(?) the feature you are describing. Was the behavior changed in the v2.0.0 release or later on?

@yunyun27
Copy link
Author

It "broke" in the v3.0.0 release. Thank you!

@yunyun27
Copy link
Author

I am so sorry, I just realized there are a bunch of minor versions between v2 and v3.
It actually broke in the v.2.2.0 release. In other words, v.2.1.0 works fine. Thanks!

@breautek
Copy link

These are the changes between v2.1.0 and v2.2.0

rel/2.1.0...rel/2.2.0

@gormlabenz
Copy link

Had the same issue on ios, didn't test it on andorid. Downgrading from 5.0 to 2.0 solved the issue.

@gormlabenz
Copy link

Version 4.0 is also working

@Heshyo
Copy link

Heshyo commented Jan 26, 2021

I don't know if it's linked to #293 (comment) , but I also fixed my issue on iOS by reverting from 5.0.3 to 4.0.

@goffioul
Copy link

I believe this is due to 00ddb93. For remote streams, the plugin does not keep track of the created AVPlayer instance and keeps overwriting a single CDVSound avPlayer field. This has then various knock-off effects, e.g. create 2 sounds with different URL, the second one overwrite the AVPlayer of the first one and they both end up controlling the same playback:

s1 = new Media(url_1);
s1.play();
s2 = new Media(url_2);  // <-- s1 stops playing
s2.play();
s1.pause();  // <-- s2 pauses
s1.play();   // <-- s2 resumes

I think you can also run into inconsistencies with one remote and one local sound, although I haven't actually tested it: create a remote sound, then create a local sound, then play the local sound. Because the logic only checks for the presence of avPlayer (https://github.com/apache/cordova-plugin-media/blob/master/src/ios/CDVSound.m#L384), I think it might start playing the remote sound instead (just a guess, though).

Unfortunately, it seems the iOS implementation of the plugin is badly unmaintained. Whatever the reasons were to use different code path (AVPlayer vs. AVAudioPlayer) for local and remote streams, I don't think these are still relevant nowadays.

@ghenry22
Copy link
Contributor

ghenry22 commented Jun 6, 2022

The plugin was originally written only with avaudioplayer. This framework does not support streaming audio, it will download an entire file and then play it.

So the avplayer implementation was added so that streaming sources would use avplayer so that media streaming worked properly.

I have a fork of the plugin that I have been working on slowly removing the avaudioplayer code completely so that everything just uses avplayer as it supports both file and streaming sources. There is a lot of cruft in this plugin though so it is slow going cleaning it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants