-
Notifications
You must be signed in to change notification settings - Fork 286
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
Local media does not work on Android #200
Comments
I had the same problem recently. I have not seen any documentation on this, but it seems like local playback (from asset folder bundled in app) does not work with this plugin on Android. It's probably a security issue causing the plugin to not be able to get the file in the bundled file structure. I used a workaround on Android, but it's far from perfect. Please see the two approaches for iOS and Android below. Setup: In Ionic/Cordova the File plugin is needed:
With Ionic/Cordova I also needed to reference cordova.js in my project index.html file: To be honest, I'm not sure if needed, but I also add the Cordova File plugin in my config.xml along with the straming media plugin: Again, I am not sure if needed, but I also have the Cordova Whitelist plugin added: ..with a bunch of paths allowed: I also add these permissions: Playback on iOS is quite straight forward:
I used a workaround on Android, but it's far from perfect. My approach is to copy the file from the applicationDirectory (in the bundled file structure) to the dataDirectory (storage available to the app):
This is definitely a workaround to get it to work on Android and absolutely not a perfect solution. Main drawbacks:
I tried to get the Ionic native video player to work (com.moust.cordova.videoplayer), but without success. Maybe this plugin allows playback from the asset folder? |
@nettopuis thank you for this, copying the file to the data directory does work on Android. I had to modify your code a bit to work, specifically I would still consider this a "bug" in this plugin, but this is a valid workaround. Thanks again! |
Thank you for this great plugin! I would love to use it, but I think I have found a bug.
What version of Streaming-Meda-Cordova-Plugin are you using?
latest
What version of Cordova are you using?
8.0.0
What devices are affected?
Android
Please describe the issue in detail, with relevant code samples
I have all audio and video working on iOS and Android when using full paths, such as https://mysite.com/file.mp3. Local files (in the application directory) work on iOS, but not Android.
On Android, when I attempt to play a local file, such as www/assets/file.mp3, a blank player opens and nothing happens. No errors, no controls, no sound, nothing.
I am using
streamingMedia.playAudio( cordova.file.applicationDirectory + 'www/assets/file.mp3' )
for the filepath, and I have confirmed that the path is correct, and the correct file exists at this path. I can play it using HTML5 audio at this exact path, it also works on iOS.I have tried relative urls, and every local path imaginable, no local files work on Android. I have tested on a device and using the emulator, the behavior is the same.
Any help would be amazing. Thanks!
The text was updated successfully, but these errors were encountered: