Phonegap + iOS: how to play audio with Media API - ios

i have an audio file test.mp3.
when the file located in "Documents" folder, and i create my media object like this :media = new Media('documents://test.mp3'); Everything works fine.
but when my audio file located in a subfolder in "Documents" folder, say "Documents/data", and i create my media object like this: media = new Media('documents://data/test.mp3'), i have this error in console: Failed to initialize AVAudioPlayer: (null) . And error code = 4
My question is, how can i play an audio file located in a subfolder in "Documents" folder
Edited:
It is fixed in phonegap 1.3.0

Using phonegap 1.7, just provide the name of the file without any schema. According to the Cordova source code if you don't prefix with any schema (like documents/file) it is relative to your www fold
media = new Media('test.mp3');
Assuming you have www/test.mp3 file in your project

Related

List of files in flutter

I have images and I want to load them to my appplication.
my_app/lib/... - here my source files
my_app/assets/images/... - here my images
I need to get list of files in assets/images/ and after that show some of them (according to other logic)
I'm trying this
final dir = Directory("assets/images/");
print(dir.existsSync()); // <---- it also print: false
var files = dir.listSync().toList();
files.forEach((e) => list.add(MyImageItem(e.path)));
The problem is: I recieve exception
FileSystemException: Directory listing failed, path = 'assets/images/'
(OS Error: No such file or directory, errno = 2)
I've tried different ways: assets/images/, images/, images and so on
My pubspec.yaml
flutter:
assets:
- assets/images/
- assets/
When I create Image directly all is fine
new Image(image: AssetImage("assets/images/cat.png"))
I knew that previously (month ago) each resource has to be declared in pubspec.yaml directly, but now assets/images/ is ok.
I can load file by direct path. Why I can't access a directory? How to get list of files in directory to get them from my code?
When you add files to your assets, it means that you already know their paths.
Store all the images paths in a list and access them whenever you need.
For example if you have 3 images in
your_app/assets/images/image1.jpg
your_app/assets/images/image2.jpg
your_app/assets/images/image3.jpg
create a list and store all of them like:
List<String> imagePaths = ['assets/images/image1.jpg', 'assets/images/image2.jpg', 'assets/images/image3.jpg'];
and for example if you want to access your first image, use
AssetImage(imagePaths[0])
I keep a json file inside assets which records the file tree of assets folder.
When file list is needed, I just read from the json file.
Such json file can be easily generated by code.
However, this does not solve your problem directly when u have 5-10k images.
Only one json file might be too large to read.
Images should be grouped and recorded in separated json files.

Application private directory on iOS with access to creation of files from Qt APIs

I am using Qt app on iOS & want to save files into Application's private directory so that other apps cannot access my files. Reading through the documentation here, /Documents directory under data container looks to be the path to save my files which are private to app.
Firstly I chose to use QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) which returned
/var/mobile/Containers/Data/Application/123XX-XXXX-XXXX-XXXX/Library/Application Support/MyApp. But then I found that I could not create any files in there. Tried /Documents inside the App folder as well. But in vain.
Secondly I tried QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) which returned /var/mobile/Containers/Data/Application/123XX-XXXX-XXXX-XXXX/Documents. I am able to create & save my files here.
On iOS, which is the correct path to create files which are meant to be private to the application ?
How can I get the path using Qt?
The directory named with some ID as 123XX-XXXX-XXXX-XXXX, Is this the application directory or is it Library/Application Support/MyApp inside the same directory ?
I had same problem, for example I created a sqlite file. But the file that you will create can be every file you wants. In my example I need to create a sqlite file.
I solved like this:
QString dbName = "mydb.sql";
QString dbLocation;
#ifdef Q_OS_ANDROID
dbLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
#endif
#ifdef Q_OS_IOS
dbLocation = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(dbLocation + "/" + dbName);
qDebug() << db.database(dbLocation + "/" + dbName);
qDebug() << db.databaseName();
Now you can save the file, I used DocumentsLocation to get a path, always works on iOS, but not work on Android, to be ready to Android you use another path: AppDataLocation.
In the documents location you can write/read/put and create files on iOS.
In the AppDataLocation location you can write/read/put and create files on Android.
Permission not denied in DocumentsLocation.

React-native-sqlite-storage how to open database in documents directory for iOS

I am using react-native-sqlite-storage and I can not find a way to get it to open a database that is already in documents directory (downloaded from internet). The file name specified seems to point to a file in the app bundle, which when running on iOS is copied by the library from the bundle to the app's Library folder (since you cant modify files in the iOS app bundle). How can I force it to make use of a file already in the documents folder (or library folder if i move it there)?
React-Native-Sqlite-Storage uses a subdirectory within the apps library folder. The directory is called localDatabase. Copy, or download, or move your database to that location (localDatabase), and then open the database using React-Native-Sqlite-Storage's openDatabase() function while giving it the database name.
var RNFS = require('react-native-fs');
var SQLite = require('react-native-sqlite-storage');
/*copy file from app bundle to library/localDatabase*/
var sourcePath = RNFS.MainBundlePath + '/' + 'myDatabase.sqlite';
var destinPath = RNFS.RNFS.LibraryDirectoryPath + '/LocalDatabase/' + 'myDatabase.sqlite';
RNFS.copyFile(sourcePath, destinPath)
.then(() =>{
var db = SQLite.openDatabase("myDatabase.sqlite", "1.0", "", 200000, me._openCB, me._errorCB);
})

Air iOS Flash, what is the included folder path?

This is kinda silly but I can't seem to find the directory path for the included folder.
In Flash Cs6 publish setting, I included a folder which is located at c:\abc\def\ghi/xxx.
In this case, the path in iOS will be app://xxx?
To access a flle in the folder, what string do I exactly need to pass to the URLRequest?
I think you are trying to access applicationDirectory. In iOS standard directories native path like
app:/ means applicationDirectory
applicationDirectory - /var/mobile/Applications/uid/filename.app
applicationStorageDirectory - /var/mobile/Applications/uid/Library/Application Support/applicationID/Local Store
However you can access application directory file like
var applicationXMLFile:File = File.applicationDirectory.resolvePath("application_data.xml");
var applicationXMLUpdateFile:File = new File(applicationXMLFile.nativePath);
if we are trying access directly like
var applicationXMLFile:File = File.applicationDirectory.resolvePath("application_data.xml");
Sometimes it throws SecurityError/IOError.
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7d9e
Using a File.
If you want pass to URLRequest iOS Documents folder path.
try this:
var urlRequest:URLRequest = new URLRequest(File.documentsDirectory.resolvePath("myFile.txt").nativePath);

FTPHelper library not working iOS

Hello I have this code and don't download anything...
FTPHelper *ftp;
ftp.urlString = #"ftp.marignal.com";
ftp.uname = #"whttpapp.marignal.com";
ftp.pword = #"hidden";
ftp.filePath = #"Barcos/Imagenes";
[ftp download:#"catlanza.bmp"];
I'm using this lib: https://github.com/erica/iphone-3.0-cookbook-/tree/master/C13-Networking/15-FTP%20Helper
That method download, It suppose to install the selected file in Documents directory...
Look in the simulator for the path it copied to.
Likely you need to tack on Documents:
ftp.filePath = #"Documents/Barcos/Imagenes";
Or get the path programmatically:
What is the documents directory (NSDocumentDirectory)?

Resources