apache / cordova-plugin-media

Apache Cordova Media Plugin
https://cordova.apache.org/
Apache License 2.0
390 stars 763 forks source link

i can't play audio in cordova 12 #389

Open metalalchemist opened 6 months ago

metalalchemist commented 6 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

notboring commented 5 months ago

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 commented 5 months ago

do you search any forks of this project? i see one fork that was updated 1 week ago. i see that modified te soundcontroller.m in ios src directory.

2024-01-08 8:34 GMT-08:00, Malte Köhrer @.***>:

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.

-- Reply to this email directly or view it on GitHub: https://github.com/apache/cordova-plugin-media/issues/389#issuecomment-1881428103 You are receiving this because you authored the thread.

Message ID: @.***>

metalalchemist commented 5 months ago

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 commented 5 months ago

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.

https://github.com/apache/cordova-plugin-media/pull/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 commented 5 months ago

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

metalalchemist commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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?