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

i can't play audio in cordova 12 #389

Open
metalalchemist opened this issue Dec 18, 2023 · 14 comments
Open

i can't play audio in cordova 12 #389

metalalchemist opened this issue Dec 18, 2023 · 14 comments

Comments

@metalalchemist
Copy link

metalalchemist commented Dec 18, 2023

hello, when i tried to replay a local file.mp3 i can't.
i am using cordova plugin media the latest version xcode 15 and macos sonoma 14.1
i tried compile in iphone SE 3rd generation with ios 16.6.1
i loaded file in "sounds/file.mp3"
the file is located in www/sounds/file.mp3
the succes funtion is invoqued, like the audio was playing.
i am using ios platform 7.0.0
thanx, my english is so bad.

@notboring
Copy link

notboring commented Jan 5, 2024

Try to use XCode 14.2 on an older version of OSX. I tried to port a cordova ios 7 project that had working audio with XCode 14.2 to XCode 15 during the last weeks but found no way to play audio using this plugin with that XCode version. If you don't want to reinstall your mac you could install the older OSX/XCode versions inside a virtual machine.

@metalalchemist
Copy link
Author

metalalchemist commented Jan 5, 2024

did you belive that i need to downgrade my macos to 13.6? i think to downgrade only my xcode to 14.3,
only i downloaded xcode and i think to do in terminal:
sudo xcode select -s xcode14.3.app
but di you try this solution? i think that you need delete the platforms especifically i downloaded ios 17.2 and ios 16.0 to iPhone 8 plush.
i think delete it, and reinstall in xcode 14.3 then.
try it and tellme if you solved your iswe.
i think that i can't downgrade my macos, because is a 2011 mac and i am executing with open core i don't have to mutch memory and procesor.

@metalalchemist
Copy link
Author

do you try with xcode 15.1 beta?
the latest beta.

@notboring
Copy link

do you try with xcode 15.1 beta? the latest beta.

I am using the Xcode 15.1 release. I did not test this using the new 15.2 beta in case you are referring to that version.

As for your questions about using XCode 14.3 with the latest OSX version, I can't really help you. I tried to use XCode 14.2 on sonoma by calling the executable from the command line which disables the OSX version check but it failed compiling the project, didn't allow you to use external swift libraries and crashed on code completition.

@metalalchemist
Copy link
Author

metalalchemist commented Jan 8, 2024 via email

@metalalchemist
Copy link
Author

aditionally i found a way to open xcode 14 in macos in stackoverflow.

https://stackoverflow.com/questions/76958016/is-there-a-way-to-run-xcode-14-on-macos-sonoma
do you tried it?

@notboring
Copy link

notboring commented Jan 9, 2024

I finally figured out why audio didn't play back for me. This was caused by cordova-plugin-media 7.0 and is not related to XCode 15.1. It seems I accidently updated cordova-plugin-media to 7 while fixing another bug that really was caused by XCode 15.

#362 changed the behaviour for parsing file paths. You now need to use paths starting with / instead of "relative" paths or simple filenames. If the file is in www/assets/sounds/theme.mp3 you now need to load it from "/assets/sounds/theme.mp3". Previously you could load it by using "assets/sounds/theme.mp3" but this won't work anymore with that pull request.

The documentation isn't fully up to date yet, it still says "order of file search: When only a file name or simple path is provided, iOS searches in the www directory for the file, then in the application's documents/tmp directory:". That's not the case anymore.

@metalalchemist
Copy link
Author

what cordova version do you use?
sorry, my english is so bad.

@metalalchemist
Copy link
Author

my theme is in www/sounds, so i wrote
new media("/sounds/theme.mp3") but i don't get sound.
this is the correct sintax? or
"/assets/www/sounds/theme.mp3"

@metalalchemist
Copy link
Author

can you giveme one example please? i'm use cordova 12.0, maybe do you use cordova 11.1?
please tellme. any information can helpme.

@notboring
Copy link

notboring commented Jan 10, 2024

I use Cordova 12/Cordova iOs 7/Cordova Media Plugin 7.

The path is looking good. Did you start the playback of the Media?

let sound=new Media("/sounds/theme.mp3"); sound.play()

This is directly copied from my project and works for me:

event = new Media( getAssetPath() + soundId + '.mp3'); event.play({playWhenScreenIsLocked:false}); event.setVolume(0.9);

Note: getAssetPath() would just return /sounds/ for iOs if this was your project.

@metalalchemist
Copy link
Author

getaccetpath is a cordova function or is your function.
i'm using all that your say and not working. this is in my index.js then of deviceready.
function playAudio(src) {
musica = new Media("/sounds/"+src+".mp3", null, null, function (status) { if (status === Media.MEDIA_STOPPED) musica.play({playAudioWhenScreenIsLocked: false});});
musica.play({playAudioWhenScreenIsLocked: false});
}
i'm using macos 14.1
when i using ventura this worked for me except i added the / like you say me.
i think that the problem is my mac, because i am using open core.
i am using 3 Media players to play audio, one for te music, other for ambience and other for effects.
maybe i can use only one? but, in ventura i can use 3 Media like i say you.

@metalalchemist
Copy link
Author

can you test my code in one of your projects? only a test?
i write the other params one for succes, error, and waths append when the music stops. do you think if this is the problem?
do you think that i should write only with the src path?
thanks, please helpme.

@metalalchemist
Copy link
Author

one thing that i see is that event.setVolume(0.9); now is an int. but before this property i had to write like a string. example
event.setVolume("0.9");
wath is the correct way now?

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

2 participants