-
Notifications
You must be signed in to change notification settings - Fork 765
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
Can't play mp3 - No such file / Failed to connect to localhost #401
Comments
There's a few things to unpack here, most of which doesn't make much sense:
This path suggests that you have your There are limitations in using external storage through File APIs, though I do not think they apply to
As I stated above,
If you're using the file transfer plugin to "download" from
the Moving forward....Because there is a lot of weird constructs in the information you've provided, we will need a sample reproduction app that demonstrates the issue. This will help isolate the bug from your application code and allows others to easily reproduce the issue. If the issue cannot be reproduced in a minimal sample application, then it suggests that the bug doesn't rely in the media plugin. |
I must say, much of this doesn't make sense to me either. That's why I'm posting here. One thing I will say is my app was created quite a long time ago, and at that time it was advantageous to install to SD card if so I used installLocation of "prefer external". My I tried I am using the file-transfer plugin to download from an online web location to the device. I can see a file produced on the device when I download to The errors I'm experiencing are not related to the file-transfer plugin. That plugin works fine. The error occurs when I try to play a file I downloaded with the media plugin. I understand that using the Perhaps you can respond to the above before I go about trying to figure out how to create a sample reproduction app? I appreciate your time. I do think that creating a new app from scratch with internal instead of external settings would be worthwhile and would potentially solve my problem for future apps. |
My apologies, I got confused between
You should have a
Android has became much more stricter in attempt to provide greater privacy to the end-user. Since API 29 accessing the external file system (e.g. anything inside
This part I'm not sure if I'm completely understanding. Suppose your loaded document is at It sounds like you're using the file transfer plugin to download a mp3 to my_media = new Media("test.mp3", ... So now we have this code snippet, that relatively loads in If you want to use the downloaded file, you'll need to get the FileEntry object using the file plugin. With the An example/untested code might look like: let path = cordova.file.applicationStorageDirectory + "/test.mp3";
window.resolveLocalFilesystemURI(path, function(fileEntry) {
let media = new Media(fileEntry.toURL());
...
}, onError); Let me know if this helps. |
When using the toURL with value for example "https://localhost/__cdvfile_files__/A_casa_vete_y_cuenta_alli.mp3" I get this error:
I suspect any https://localhost URL would give me this error. |
You're suspicion is right. It seems like the plugin is passing through the In fact I don't think the URL is being loaded through the webview, I think the URL is just being passed via the media plugin... Given that information, then I think this should work let path = cordova.file.applicationStorageDirectory + "/test.mp3";
let media = new Media(path); You may want to double check the value of |
Alternatively, you can probably use the native browser feature as well instead of the media plugin. let path = cordova.file.applicationStorageDirectory + "/test.mp3";
window.resolveLocalFilesystemURI(path, function(fileEntry) {
let audio = new Audio(fileEntry.toURL());
audio.play();
...
}, onError); As an example, or you can create a audio node via The Depending on your use cases, the usage of the media plugin might not be necessary. The HTML5 Audio/Video APIs are widely supported nowadays. |
Using
I will have to experiment with the native browser feature. |
When trying the native browser code (resolveLocalFileSystemURI) I get
|
Would you suggest building a new app as the next step then? I haven't been able to play audio on the device as of yet. |
Update: I just tried kiot-cordova-plugin-nativeaudio and it can play a resource in the www folder no problem with my existing app. Unfortunately, it doesn't sound like I can download to that location or copy a file there, so I'm still stuck. Good to know I can still play native audio though. After some digging I'm not seeing any other obvious alternatives out there that have been recently maintained. Sounds like I may have to publish two versions of the app - one with native audio and one with streaming audio? |
Does this have anything to do with this? I doubt it... but at any rate, at some reason the file transfer plugin is downloading only partial files so I tried going to the file plugin method and ran into a CORS issue. This is just chaos to me... I'm thinking I will tell this requester/client that I just cannot fulfill their request. I have spent too many hours of fruitless effort on it. I'm just not smart enough to figure it out. |
Bug Report
Problem
I cannot play mp3 files with the plugin apart from those on my online server.
What is expected to happen?
Play mp3 file. I believe this worked a long time ago but no longer works now...
What does actually happen?
Get error:
/storage/emulated/0/Android/data/com.hablamedecristo.himnario2/files/test.mp3: open failed: ENOENT (No such file or directory)
Note: when trying to access an mp3 file with cordova.file.applicationStorageDirectory or https://localhost/test.mp3, I get the error "java.net.ConnectException: Failed to connect to localhost/127.0.0.1:443"
Information
Command or Code
I have test.mp3 saved in the android/platform_www directory. I also can download to cordova.file.applicationStorageDirectory via the cordova-plugin-file-transfer plugin.
config.xml
Content Security Policy
Environment, Platform, Device
Android Target SDK = 34
Galaxy Tab A7, Android 12
Version information
Cordova version 12.0.0
cordova-media-plugin version 7.0.0
cordova-plugin-file version 8.1.0
cordova-plugin-file-transfer version 2.0.0
Android Studio Koala 2024.1.1 Patch 2
Checklist
The text was updated successfully, but these errors were encountered: