mobile_template 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/bin/mobile_template +71 -0
- data/lib/mobile_template/version.rb +4 -0
- data/lib/mobile_template.rb +5 -0
- data/mobile_template.gemspec +21 -0
- data/templates/assets/Gemfile +4 -0
- data/templates/assets/config.rb +96 -0
- data/templates/assets/config.ru +4 -0
- data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
- data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
- data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
- data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
- data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
- data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
- data/templates/assets/source/index.html.erb +2 -0
- data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
- data/templates/assets/source/javascripts/application.js.coffee +5 -0
- data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
- data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
- data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
- data/templates/assets/source/layout.erb +24 -0
- data/templates/assets/source/stylesheets/application.css.scss +2 -0
- data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
- data/templates/cordova_android/.gitignore +18 -0
- data/templates/cordova_android/LICENSE +202 -0
- data/templates/cordova_android/NOTICE +5 -0
- data/templates/cordova_android/README.md +95 -0
- data/templates/cordova_android/VERSION +1 -0
- data/templates/cordova_android/bin/BOOM +4 -0
- data/templates/cordova_android/bin/autotest +2 -0
- data/templates/cordova_android/bin/bench +29 -0
- data/templates/cordova_android/bin/create +46 -0
- data/templates/cordova_android/bin/create.bat +1 -0
- data/templates/cordova_android/bin/create.js +88 -0
- data/templates/cordova_android/bin/create.xml +79 -0
- data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
- data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
- data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
- data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
- data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
- data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
- data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
- data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
- data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
- data/templates/cordova_android/bin/test +26 -0
- data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
- data/templates/cordova_android/bin/tests/create.coffee +21 -0
- data/templates/cordova_android/bin/tests/debug.coffee +0 -0
- data/templates/cordova_android/bin/tests/test.coffee +0 -0
- data/templates/cordova_android/framework/.classpath +8 -0
- data/templates/cordova_android/framework/.project +33 -0
- data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
- data/templates/cordova_android/framework/ant.properties +34 -0
- data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
- data/templates/cordova_android/framework/assets/js/app.js +89 -0
- data/templates/cordova_android/framework/assets/js/battery.js +134 -0
- data/templates/cordova_android/framework/assets/js/camera.js +168 -0
- data/templates/cordova_android/framework/assets/js/capture.js +203 -0
- data/templates/cordova_android/framework/assets/js/compass.js +168 -0
- data/templates/cordova_android/framework/assets/js/contact.js +310 -0
- data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
- data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
- data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
- data/templates/cordova_android/framework/assets/js/device.js +83 -0
- data/templates/cordova_android/framework/assets/js/file.js +1082 -0
- data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
- data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
- data/templates/cordova_android/framework/assets/js/header.txt +19 -0
- data/templates/cordova_android/framework/assets/js/media.js +233 -0
- data/templates/cordova_android/framework/assets/js/network.js +100 -0
- data/templates/cordova_android/framework/assets/js/notification.js +133 -0
- data/templates/cordova_android/framework/assets/js/position.js +100 -0
- data/templates/cordova_android/framework/assets/js/storage.js +439 -0
- data/templates/cordova_android/framework/assets/www/index.html +27 -0
- data/templates/cordova_android/framework/build.xml +216 -0
- data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
- data/templates/cordova_android/framework/proguard-project.txt +20 -0
- data/templates/cordova_android/framework/project.properties +14 -0
- data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
- data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
- data/templates/cordova_android/framework/res/layout/main.xml +29 -0
- data/templates/cordova_android/framework/res/values/strings.xml +23 -0
- data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
- data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
- data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
- data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
- metadata +279 -0
@@ -0,0 +1,364 @@
|
|
1
|
+
/*
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
4
|
+
distributed with this work for additional information
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
7
|
+
"License"); you may not use this file except in compliance
|
8
|
+
with the License. You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
13
|
+
software distributed under the License is distributed on an
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
KIND, either express or implied. See the License for the
|
16
|
+
specific language governing permissions and limitations
|
17
|
+
under the License.
|
18
|
+
*/
|
19
|
+
package org.apache.cordova;
|
20
|
+
|
21
|
+
import android.content.Context;
|
22
|
+
import android.media.AudioManager;
|
23
|
+
import java.util.ArrayList;
|
24
|
+
|
25
|
+
import org.apache.cordova.api.LOG;
|
26
|
+
import org.apache.cordova.api.Plugin;
|
27
|
+
import org.apache.cordova.api.PluginResult;
|
28
|
+
import org.json.JSONArray;
|
29
|
+
import org.json.JSONException;
|
30
|
+
|
31
|
+
import java.util.HashMap;
|
32
|
+
import java.util.Map.Entry;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* This class called by CordovaActivity to play and record audio.
|
36
|
+
* The file can be local or over a network using http.
|
37
|
+
*
|
38
|
+
* Audio formats supported (tested):
|
39
|
+
* .mp3, .wav
|
40
|
+
*
|
41
|
+
* Local audio files must reside in one of two places:
|
42
|
+
* android_asset: file name must start with /android_asset/sound.mp3
|
43
|
+
* sdcard: file name is just sound.mp3
|
44
|
+
*/
|
45
|
+
public class AudioHandler extends Plugin {
|
46
|
+
|
47
|
+
public static String TAG = "AudioHandler";
|
48
|
+
HashMap<String,AudioPlayer> players; // Audio player object
|
49
|
+
ArrayList<AudioPlayer> pausedForPhone; // Audio players that were paused when phone call came in
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Constructor.
|
53
|
+
*/
|
54
|
+
public AudioHandler() {
|
55
|
+
this.players = new HashMap<String,AudioPlayer>();
|
56
|
+
this.pausedForPhone = new ArrayList<AudioPlayer>();
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Executes the request and returns PluginResult.
|
61
|
+
*
|
62
|
+
* @param action The action to execute.
|
63
|
+
* @param args JSONArry of arguments for the plugin.
|
64
|
+
* @param callbackId The callback id used when calling back into JavaScript.
|
65
|
+
* @return A PluginResult object with a status and message.
|
66
|
+
*/
|
67
|
+
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
68
|
+
PluginResult.Status status = PluginResult.Status.OK;
|
69
|
+
String result = "";
|
70
|
+
|
71
|
+
try {
|
72
|
+
if (action.equals("startRecordingAudio")) {
|
73
|
+
this.startRecordingAudio(args.getString(0), args.getString(1));
|
74
|
+
}
|
75
|
+
else if (action.equals("stopRecordingAudio")) {
|
76
|
+
this.stopRecordingAudio(args.getString(0));
|
77
|
+
}
|
78
|
+
else if (action.equals("startPlayingAudio")) {
|
79
|
+
this.startPlayingAudio(args.getString(0), args.getString(1));
|
80
|
+
}
|
81
|
+
else if (action.equals("seekToAudio")) {
|
82
|
+
this.seekToAudio(args.getString(0), args.getInt(1));
|
83
|
+
}
|
84
|
+
else if (action.equals("pausePlayingAudio")) {
|
85
|
+
this.pausePlayingAudio(args.getString(0));
|
86
|
+
}
|
87
|
+
else if (action.equals("stopPlayingAudio")) {
|
88
|
+
this.stopPlayingAudio(args.getString(0));
|
89
|
+
} else if (action.equals("setVolume")) {
|
90
|
+
try {
|
91
|
+
this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
|
92
|
+
} catch (NumberFormatException nfe) {
|
93
|
+
//no-op
|
94
|
+
}
|
95
|
+
} else if (action.equals("getCurrentPositionAudio")) {
|
96
|
+
float f = this.getCurrentPositionAudio(args.getString(0));
|
97
|
+
return new PluginResult(status, f);
|
98
|
+
}
|
99
|
+
else if (action.equals("getDurationAudio")) {
|
100
|
+
float f = this.getDurationAudio(args.getString(0), args.getString(1));
|
101
|
+
return new PluginResult(status, f);
|
102
|
+
}
|
103
|
+
else if (action.equals("release")) {
|
104
|
+
boolean b = this.release(args.getString(0));
|
105
|
+
return new PluginResult(status, b);
|
106
|
+
}
|
107
|
+
return new PluginResult(status, result);
|
108
|
+
} catch (JSONException e) {
|
109
|
+
e.printStackTrace();
|
110
|
+
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Identifies if action to be executed returns a value and should be run synchronously.
|
116
|
+
*
|
117
|
+
* @param action The action to execute
|
118
|
+
* @return T=returns value
|
119
|
+
*/
|
120
|
+
public boolean isSynch(String action) {
|
121
|
+
if (action.equals("getCurrentPositionAudio")) {
|
122
|
+
return true;
|
123
|
+
}
|
124
|
+
else if (action.equals("getDurationAudio")) {
|
125
|
+
return true;
|
126
|
+
}
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Stop all audio players and recorders.
|
132
|
+
*/
|
133
|
+
public void onDestroy() {
|
134
|
+
for (AudioPlayer audio : this.players.values()) {
|
135
|
+
audio.destroy();
|
136
|
+
}
|
137
|
+
this.players.clear();
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Called when a message is sent to plugin.
|
142
|
+
*
|
143
|
+
* @param id The message id
|
144
|
+
* @param data The message data
|
145
|
+
*/
|
146
|
+
public void onMessage(String id, Object data) {
|
147
|
+
|
148
|
+
// If phone message
|
149
|
+
if (id.equals("telephone")) {
|
150
|
+
|
151
|
+
// If phone ringing, then pause playing
|
152
|
+
if ("ringing".equals(data) || "offhook".equals(data)) {
|
153
|
+
|
154
|
+
// Get all audio players and pause them
|
155
|
+
for (AudioPlayer audio : this.players.values()) {
|
156
|
+
if (audio.getState() == AudioPlayer.MEDIA_RUNNING) {
|
157
|
+
this.pausedForPhone.add(audio);
|
158
|
+
audio.pausePlaying();
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
}
|
163
|
+
|
164
|
+
// If phone idle, then resume playing those players we paused
|
165
|
+
else if ("idle".equals(data)) {
|
166
|
+
for (AudioPlayer audio : this.pausedForPhone) {
|
167
|
+
audio.startPlaying(null);
|
168
|
+
}
|
169
|
+
this.pausedForPhone.clear();
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
//--------------------------------------------------------------------------
|
175
|
+
// LOCAL METHODS
|
176
|
+
//--------------------------------------------------------------------------
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Release the audio player instance to save memory.
|
180
|
+
*
|
181
|
+
* @param id The id of the audio player
|
182
|
+
*/
|
183
|
+
private boolean release(String id) {
|
184
|
+
if (!this.players.containsKey(id)) {
|
185
|
+
return false;
|
186
|
+
}
|
187
|
+
AudioPlayer audio = this.players.get(id);
|
188
|
+
this.players.remove(id);
|
189
|
+
audio.destroy();
|
190
|
+
return true;
|
191
|
+
}
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Start recording and save the specified file.
|
195
|
+
*
|
196
|
+
* @param id The id of the audio player
|
197
|
+
* @param file The name of the file
|
198
|
+
*/
|
199
|
+
public void startRecordingAudio(String id, String file) {
|
200
|
+
// If already recording, then just return;
|
201
|
+
if (this.players.containsKey(id)) {
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
AudioPlayer audio = new AudioPlayer(this, id);
|
205
|
+
this.players.put(id, audio);
|
206
|
+
audio.startRecording(file);
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Stop recording and save to the file specified when recording started.
|
211
|
+
*
|
212
|
+
* @param id The id of the audio player
|
213
|
+
*/
|
214
|
+
public void stopRecordingAudio(String id) {
|
215
|
+
AudioPlayer audio = this.players.get(id);
|
216
|
+
if (audio != null) {
|
217
|
+
audio.stopRecording();
|
218
|
+
this.players.remove(id);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Start or resume playing audio file.
|
224
|
+
*
|
225
|
+
* @param id The id of the audio player
|
226
|
+
* @param file The name of the audio file.
|
227
|
+
*/
|
228
|
+
public void startPlayingAudio(String id, String file) {
|
229
|
+
AudioPlayer audio = this.players.get(id);
|
230
|
+
if (audio == null) {
|
231
|
+
audio = new AudioPlayer(this, id);
|
232
|
+
this.players.put(id, audio);
|
233
|
+
}
|
234
|
+
audio.startPlaying(file);
|
235
|
+
}
|
236
|
+
|
237
|
+
/**
|
238
|
+
* Seek to a location.
|
239
|
+
*
|
240
|
+
*
|
241
|
+
* @param id The id of the audio player
|
242
|
+
* @param miliseconds int: number of milliseconds to skip 1000 = 1 second
|
243
|
+
*/
|
244
|
+
public void seekToAudio(String id, int milliseconds) {
|
245
|
+
AudioPlayer audio = this.players.get(id);
|
246
|
+
if (audio != null) {
|
247
|
+
audio.seekToPlaying(milliseconds);
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Pause playing.
|
253
|
+
*
|
254
|
+
* @param id The id of the audio player
|
255
|
+
*/
|
256
|
+
public void pausePlayingAudio(String id) {
|
257
|
+
AudioPlayer audio = this.players.get(id);
|
258
|
+
if (audio != null) {
|
259
|
+
audio.pausePlaying();
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
/**
|
264
|
+
* Stop playing the audio file.
|
265
|
+
*
|
266
|
+
* @param id The id of the audio player
|
267
|
+
*/
|
268
|
+
public void stopPlayingAudio(String id) {
|
269
|
+
AudioPlayer audio = this.players.get(id);
|
270
|
+
if (audio != null) {
|
271
|
+
audio.stopPlaying();
|
272
|
+
//audio.destroy();
|
273
|
+
//this.players.remove(id);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* Get current position of playback.
|
279
|
+
*
|
280
|
+
* @param id The id of the audio player
|
281
|
+
* @return position in msec
|
282
|
+
*/
|
283
|
+
public float getCurrentPositionAudio(String id) {
|
284
|
+
AudioPlayer audio = this.players.get(id);
|
285
|
+
if (audio != null) {
|
286
|
+
return(audio.getCurrentPosition()/1000.0f);
|
287
|
+
}
|
288
|
+
return -1;
|
289
|
+
}
|
290
|
+
|
291
|
+
/**
|
292
|
+
* Get the duration of the audio file.
|
293
|
+
*
|
294
|
+
* @param id The id of the audio player
|
295
|
+
* @param file The name of the audio file.
|
296
|
+
* @return The duration in msec.
|
297
|
+
*/
|
298
|
+
public float getDurationAudio(String id, String file) {
|
299
|
+
|
300
|
+
// Get audio file
|
301
|
+
AudioPlayer audio = this.players.get(id);
|
302
|
+
if (audio != null) {
|
303
|
+
return(audio.getDuration(file));
|
304
|
+
}
|
305
|
+
|
306
|
+
// If not already open, then open the file
|
307
|
+
else {
|
308
|
+
audio = new AudioPlayer(this, id);
|
309
|
+
this.players.put(id, audio);
|
310
|
+
return(audio.getDuration(file));
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
/**
|
315
|
+
* Set the audio device to be used for playback.
|
316
|
+
*
|
317
|
+
* @param output 1=earpiece, 2=speaker
|
318
|
+
*/
|
319
|
+
public void setAudioOutputDevice(int output) {
|
320
|
+
AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
|
321
|
+
if (output == 2) {
|
322
|
+
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
323
|
+
}
|
324
|
+
else if (output == 1) {
|
325
|
+
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
326
|
+
}
|
327
|
+
else {
|
328
|
+
System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
/**
|
333
|
+
* Get the audio device to be used for playback.
|
334
|
+
*
|
335
|
+
* @return 1=earpiece, 2=speaker
|
336
|
+
*/
|
337
|
+
public int getAudioOutputDevice() {
|
338
|
+
AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
|
339
|
+
if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) {
|
340
|
+
return 1;
|
341
|
+
}
|
342
|
+
else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) {
|
343
|
+
return 2;
|
344
|
+
}
|
345
|
+
else {
|
346
|
+
return -1;
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
/**
|
351
|
+
* Set the volume for an audio device
|
352
|
+
*
|
353
|
+
* @param id The id of the audio player
|
354
|
+
* @param volume Volume to adjust to 0.0f - 1.0f
|
355
|
+
*/
|
356
|
+
public void setVolume(String id, float volume) {
|
357
|
+
AudioPlayer audio = this.players.get(id);
|
358
|
+
if (audio != null) {
|
359
|
+
audio.setVolume(volume);
|
360
|
+
} else {
|
361
|
+
System.out.println("AudioHandler.setVolume() Error: Unknown Audio Player " + id);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}
|