Play mp3 files located in ApplicationSupportDirectory (NOT asset directory) linked from webview_flutter loaded html page - storage

I have a large number of mp3 files (+3GB) that needs to be included with the app I am writing for Android and iOS to be used offline. Since the Google Play Bundle can not be larger than 2GB, naturally I will need to download these mp3 files at initial app run-time to a local directory.
I already have a html webpage written containing all functionalities required for selecting and playing the mp3 files with synchronized screen text and backgrounds. I've also successfully load and tested my webpage offline with webview_flutter, with a limited set of mp3 files loaded in the asset directory.
Now that I needed to include all my +3GB of mp3 files, so I've downloaded them to ApplicationSupportDirectory, but it seems webview_flutter is NOT able to play mp3 files from this directory. I’ve try to place them in ApplicationSupportDirectory, ApplicationDocumentsDirectory, or ExternalStorageDirectory, but none of them can be accessed from webview_flutter’s page.
I’ve also tried to load my index.html into these non-asset directories, but get file permission error, even with Permission.storage.request() and with declared permission for READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, INTERNET in manifest.xml.
Now running out of options, do you know if it is possible to link non-asset files from webpage loaded in webview_flutter? The load string to webview method probably will not work, because I have linked audios and javascripts in the page.
Hopefully some of you can point me to a direction. Thank you in advance.

Found my own answer:
Need to setup a server between webview_flutter and non-asset directory. I've used the package local_assets_server.dart and used rootDir parameter in the LocalAssetsServer() to call and point to the local Directory path. May need to keep the assetBasePath blank. When the webview_flutter loads from this server, it will load the index.html in this rootDir path.
_initServer() async{
final server = new LocalAssetsServer(
address: InternetAddress.loopbackIPv4,
assetsBasePath: '',
rootDir: rootPath,
);
print('rootDir for server init to $rootPath');
final address = await server.serve();
print('init server address: $address');
setState(() {
this.address = address.address;
port = server.boundPort;
print('server port: $port');
isListening = true;
});
}

Related

Web view UWP not loading files in the machine

can I open a html file on the C drive or on any location using the web view in UWP?
I am using the following code but it is not working:
Uri targeturi = new Uri("C:/Users/user/Pictures/Files/Forms/dac36cac-5d83-4fae-bf4f-112361b719ea/index.html");
browser.Navigate(targeturi);
In uwp files have limited access permission. By the default the app can only access the application install directory and data locations. Additional locations require special capabilities. More details about file access permission please reference this document.
You can gain access to files and folders on a removable device by calling the file picker (using FileOpenPicker and FolderPicker) and letting the user pick files and folders for your app to access. Learn how to use the file picker in Open files and folders with a picker.
According to your code snippet, you want to access the HTML file inside the picture folder. For accessing file in picture folder please reference Files and folders in the Music, Pictures, and Videos libraries. Pay attention on the Capabilities page, select the libraries that your app manages. So the correct way to open the file and show it in the WebView may as follows:
StorageFolder storageFolder = await KnownFolders.GetFolderForUserAsync(null /* current user */, KnownFolderId.PicturesLibrary);
StorageFile indexFile = await storageFolder.GetFileAsync("index.html");/*Change to your file path inside the picture folder*/
browser.NavigateToString(await FileIO.ReadTextAsync(indexFile));
You may find I used the NavigateToString method. The Navigate(Uri) method can not navigate to a file by path directly. To load uncompressed and unencrypted content from your app’s LocalFolder or TemporaryFolder data stores, use the Navigate method with a Uri that uses the `ms-appdata scheme, to HTML content in the app package using the ms-appx-web scheme. For example:
webView1.Navigate("ms-appx-web:///help/about.html");
More details please reference "Navigating to content" of WebView. And the scenario 5 of the official sample provide samples about navigating to file you can reference.

play audio and video files in Cordova app that reside in iOS Documents directory

I have a Cordova application that I use to be able to link to mp3 and mp4 files relatively using a src like so:
../../Documents/videos/video.mp4
I just now updated my Cordova application to the latest version and these relative URLs don't work so I've been expermenting with other solutions.
It looks like if I use the cordova.file.documentsDirectory (iOS only) variable I can link to them that way but when I save references to these files in the database the GUID of the application changes and the URL is no longer valid when the app is rebuilt and relaunched.
I tried using cdvfile://localhost/persistent/ but this seems to only work for images and not video or audio files using HTML5 audio and video tags for playback.
Ultimately I could save the files with a variable that gets replaced at run-time but this is obviously not the preferred "solution." Something like [documentsfolder]/videos/video.mp4
How can I link to a persistent file location and have it work with images, audio files, and video files?
I would love to use the cdvfile url but have it work with mp3 and mp4 files.
Thank you.
You should be able to access any resource [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:#"www/[your path]"]

Cordova iOS: Load videos with downloaded html's and video files

I have the following issue:
I have an iOS Cordova Application.
The application download a zip file and decompress it in "cdvfile://localhost/persistent/content/myfolder" by ussing the following Cordova plugins: org.apache.cordova.file-transfer, org.apache.cordova.file and https://github.com/MobileChromeApps/zip.git
Inside the zip there is an "index.html" file with "video tags" on it.
I was able to succesfully load and execute the "index.html" file, but the video doesn't load.
I know that the video file was decompressed successfully because:
I check the file inside my iPad.
I embed the video in the index of the cordova app (not the downloaded one) in the following way and it works:
var videocontainer = document.getElementsByTagName('video')[0];
var videosource = document.getElementsByTagName('source')[0];
var newmp4 = cordova.file.documentsDirectory + 'content/myfolder/videos/myvideo.mp4';
videosource.setAttribute('src', newmp4);
videocontainer.load();
videocontainer.play();
But, the video is not loaded/played inside the downloaded HTML file. To understand what I'm doing, I have to develop an application that will be updated by downloading its contents from zips, and the contents includes pages with videos embeded on them. It works on PC and Android, but not in iOS.
I tried the following things:
Loading the page in "_self". The page is displayed but not the video.
Loading the page in an iframe. Same result.
Loading the page within an inAppBrowser (plugin). Same result.
Video tag with source src="videos/myvideo.mp4" (works in Web and Android). Same result.
Video tag with source src="./videos/myvideo.mp4" (works in Web and Android). Same result.
Video tag with source src= cordova.file.documentsDirectory + 'content/myfolder/videos/myvideo.mp4' (with JS, by passing the path in a query string, same path that works in the root index.html as I described before). Same result.
Video tag with source src= cordova.file.documentsDirectory + 'cdvfile://localhost/persistent/content/myfolder/videos/myvideo.mp4'. Same result.
All the combination of previous things. Same result....
Loading the downloaded resources in a DIV is not an option, because the resources (images, css, javascripts, audios, videos, etc.) are downloaded on other iOS device's folder: the app's Documents' folder (cdvfile://localhost/persistent/).
I thing I tried almost everything... Why is not trivial to play a video tag, inside an html, that are both in the app's Documents' folder???
:-(
EDIT 1: Cordova Version = 3.6.3
Solution Founded!!
In almost all the android and iOS examples, downloaded content is being executed from "cordova.file.documentsDirectory".
Then, when you link this content in a or (by using AJAX), everything works fine (CSS, images, links) but media tags ( and ).
Again, I dont know why, but almost all the examples downloads and unzip contents by using this path.
After several days being blocked with this issue (I found lots of forums where the devs have to modify all their projects by using plugins like Cordova Media, jaeger25 Html5Video, etc, etc), I tried by using the following path: "cordova.file.dataDirectory"
I download, unzip and execute the HTMLs from this path and everything works with no parsing/modifications to the HTML files (that in my case were thousands). 100% compability with and tags with relative sources' path in an IFRAME!!!!!!
I guess you code the video links into the index.html inside the zip you decompress on the device.
Those links need to get "updated" with some javascript parser, BEFORE you actually load or navigate to this page in your phonegap app.
If your example is caused in Android, you definetly need to include the HTML5 Video plugin here:
https://github.com/jaeger25/Html5Video
On iOS the tag will work for local files. But the links need to be absolute.
And the links will change if you recompile your app or reinstall it.
The files will be available, but the APP ID will have changed and the absolute path also.
Example of an iOS path:
/var/mobile/Applications/<application UUID>/Documents/path/to/file
Hope you solved your problem.

Hyperlink in SWF file published from captivate does not work

I have published a Captivate 6 file in swf format. In one the slides is a button, that when clicked executed a small piece of javascript code to open a url , using the window.open command. This link opens fine, when i publish the project as a html5 output, ie mp4 file. however , when I publish it as swf, nothing happens on clicking the button. I read somewhere that flash security settings need to be updated and you need to add the folder where swf file is , as a trusted folder. I did that but still it does not work. Then I read that this problem comes only while developing since the flash player blocks access to local files and folder, so I published this swf on a web server on , but again same problem. Would be very grateful if anyone can provide some way to solve this. Thanks.
I'm using Captivate 7 and have had countless problems with javascript, but anyways... I'll avoid ranting about that.
When you publish it as an swf are you loading it from the .htm file? I've noticed that JavaScript only "worked"(haha, if you could...ok, no ranting..) by loading it in the .htm file. When I loaded the swf directly locally or from a web server it wouldn't work.
There are three or four files in Captivate 7: swf, htm, css, and js file.
When I put all of those on the web server, and load the .htm file JavaScript... uh, "worked'.. yeah

SWF file extraction

If I have a link to a SWF file - for example here http://redletterdaysb2b.co.uk/swf/our-video.swf
how can I extract it for use on another website?
I have downloaded the swf, but just get an error#2044 when I try and play it. does it need to go in some sort of wrapper?
thanks guys
You're trying to load a swf that in turn loads and displays a .flv using the FLVPlayback component. I'm guessing our-video.swf loads fine, but it probably keeps a relative reference to the .flv.
I can think of two ways to handle this:
Simple add a new FLVPlayback (or any other video player) on the other site but tell it to load the .flv file from the original site.
Try to copy the .flv file in the same folder as the new .swf on the new site.
With the FLVPlayback component there's another part that could cause the error: the skin which on the original site is here.
The #2024 IOError should also include an URL.
This is your best hint to how the our-video.swf is trying to load the .swf file (using a relative(./swf/redletterdays.swf) or an absolute(/swf/redletterdays.swf) path).
Based on this, if you decide to load the player from the original site (not just the .flv file), you can work out where to place the skin (i.e. in the in a folder named swf on the root of the new site)

Resources