Commit 96b0bfd3 authored by Adam Monsen's avatar Adam Monsen

simplify code, update docs & app name

changed app name to TootPro
parent 04f2bf0e
# cordova-file-test
# toot-app
Demo [Meteor](https://www.meteor.com) mobile app for [this stackoverflow question](https://stackoverflow.com/questions/38800845/fileerror-code-5-trying-to-use-absolute-file-paths-with-meteor-1-4-cordova).
Demo [Meteor](https://www.meteor.com) mobile app forked from [here](https://github.com/meonkeys/cordova-file-test).
The `master` branch contains original code referred to in the stackoverflow question. The `solution` branch contains working code.
## Try it out
## How to read the code
1. Clone this repository.
1. [Install prerequisites](https://guide.meteor.com/mobile.html#installing-prerequisites-android).
1. Enable USB debugging on the device.
1. Install and run app with `meteor run android-device`.
`client/main.js` contains all the interesting bits. Hints:
## Troubleshooting
1. `git show master:client/main.js`
1. `git show solution:client/main.js`
1. `git diff master:client/main.js solution:client/main.js`
### Cannot run on Android device
Check out `mobile-config.js`, too. Having the app `id` is handy, and setting the `AndroidExtraFilesystems` permission is necessary to be able to access external storage.
I tried `meteor run android-device` and was seeing errors like this:
## Test
Status of the requirements:
✓ Java JDK
✓ Android SDK
✗ Android target: ...snipped...
✗ Gradle: ...snipped...
1. Clone this repository, checkout `solution` branch.
1. [Install prerequisites](https://guide.meteor.com/mobile.html#installing-prerequisites-android).
1. Enable USB debugging on the device.
1. Start app with `meteor run android-device`.
1. Copy a file to the device's external storage.
1. Create a text file `a` with some contents.
1. Use something like `adb push a /sdcard/Android/data/com.adammonsen.app/files/a`.
1. Open <chrome://inspect> in a browser.
1. Touch the button in the app and look for debug output in the console.
The fix was to make sure the SDK Platform with API Level "26" is installed, then run:
```bash
meteor remove-platform android
meteor add-platform android
```
## Copyright, License
Copyright (C) 2016 Adam Monsen
Copyright (C) 2018 Adam Monsen
MIT license.
......@@ -16,34 +16,12 @@ Template.hello.helpers({
},
});
function playMedia(url) {
console.log(`playMedia(${url})`);
if (Meteor.isCordova) {
// Set up to play the audio file at url
const my_media = new Media(url,
// success callback
function () {
console.log('playAudio():Audio Success');
},
// error callback
function (err) {
console.log('playAudio():Audio Error: ');
console.log(err);
}
);
// Play audio
my_media.play();
} else {
new Audio(url).play();
}
}
Template.hello.events({
'click button'(event, instance) {
// increment the counter when button is clicked
instance.counter.set(instance.counter.get() + 1);
const path = window.location.href + event.toElement.classList[0] + '.mp3';
playMedia(path);
const url = window.location.href + event.toElement.classList[0] + '.mp3';
new Audio(url).play();
},
});
......@@ -2,11 +2,9 @@
App.info({
id: 'com.adammonsen.app',
name: 'AdamApp',
description: 'Test cordorva native file operations',
name: 'TootPro™',
description: 'Simple offline sound effect app',
author: 'Adam Monsen',
email: 'haircut@gmail.com',
website: 'http://adammonsen.com'
website: 'https://adammonsen.com'
});
App.setPreference('AndroidExtraFilesystems', 'files,files-external');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment