Android Question How to set the root directory of the local http server?

watesoft

Active Member
Licensed User
Longtime User
I am using a js stave plugin called abcjs from github,It uses XmlHttpRequest to request the soundfont file on the remote server, means it uses "Http protocol" to access online soundfont file. The author of the plugin said that the soundfont file can be used locally, I download and copy it to xui.DefaultFolder,means it is "File protocal", so it always shows cross-domain errors. How to build a local http server and set xui.DefaultFolder as the root directory? because all the files are under this directory.The entire XmlHttpRequest process is written in the js plugin, I can’t modify it, all I can do is provide a URL address, like http://127.0.0.1:3000/xui.DefaultFolder.
I have seen the thread of "Embed an Http Server in your Android Application",but I don't know how to use it in my app.
I can use the following methods on the computer,and it succeeded:
E:\TEST\CIDES>http-server
Starting up http-server, serving ./
Available on:
http://192.168.0.100:8080
http://127.0.0.1:8080
Hit CTRL-C to stop the server
 
Last edited:

aeric

Expert
Licensed User
Longtime User
If you just want to get the abc.js works in Android WebView, it is easy to put the files in asset folder and load using WebViewAssetFile.
Sample attached.
 

Attachments

  • abc.zip
    296.7 KB · Views: 225
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
If you just want to get the abc.js works in Android WebView, it is easy to put the files in asset folder and load using WebViewAssetFile.
Sample attached.
Thanks aeric,I see you removed the soundFontUrl in the html, you are using the default online playback.The score can be displayed, what I need is to be able to play offline.
 
Last edited:
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
Download the quite old http server example. Search for Response.SendFile. You can set the folder there.

Thanks Erel, According to your advices, I can play the sound, but only on the Android 8 phone, Android 10 still can’t.It may be file access error, or http server lib is too old to support the current Android or Java version.
Android 8 is ok: Logs--Client: 127.0.0.1 /acoustic_grand_piano-mp3/XX.mp3
Android 10 is not ok: Logs--Didn't load note acoustic_grand_piano xx error in file:///data/user/0/b4a.HymnTest/files/abcjs-basic.js (Line: 15714)

I have uploaded the project example,you can put soundfont.zip into files folder and test. Do not unzip the sondfont.zip file.
 

Attachments

  • ABC_Test.zip
    457.7 KB · Views: 191
  • soundfont.zip
    383.8 KB · Views: 180
Upvote 0

aeric

Expert
Licensed User
Longtime User
I added the httpserver.
You need to start the server then press the Activate Audio button in WebView.
It will download the MP3 files to the cache in background I guess.
Turn off your Internet and the app can play the sound from the cache.
 

Attachments

  • abc-server.zip
    354.4 KB · Views: 198
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
I added the httpserver.
You need to start the server then press the Activate Audio button in WebView.
It will download the MP3 files to the cache in background I guess.
Turn off your Internet and the app can play the sound from the cache.
I try your example, the cache will be cleared soon. Even if the http server is not used, the cache can be generated after online playback, but the cache generally disappears in a relatively short period of time, It can be played offline for about 10-30 minutes, later the network must be reconnected to play.I have downloaded the soundfont file locally, and now it’s a problem when it is loaded.
In addition, I have hundreds of scores, and it’s troublesome to cache each of them.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
I am not familiar with JavaScript. What I see is it (abc.js) always need to download the MP3 files from the GitHub site to the cache. Unless you know how to point the url to local path.
 
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
After repeated tests, Android 8.0 can load my downloaded soundfont files through http serber, but Android 10.0 can’t. this is a strange problem.Wait and see if Erel can solve this loading problem.
 
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
I am not familiar with JavaScript. What I see is it (abc.js) always need to download the MP3 files from the GitHub site to the cache. Unless you know how to point the url to local path.


This is a reply from the author paul, he told me that it can be used locally.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…