Skip to content
Browse files

More audio experiments

  • Loading branch information...
1 parent ae48a56 commit c32c8a1486520f9ece424df5ac7ee9db81cc3707 @jash committed Jan 3, 2012
Showing with 80 additions and 5 deletions.
  1. +37 −3 audio.html
  2. +39 −0 audio2.html
  3. +4 −2 index.html
View
40 audio.html
@@ -20,18 +20,51 @@
// Record audio
mediaRec.startRecord();
- // Stop recording after 10 sec
+ // Stop recording after 5 sec
var recTime = 0;
var recInterval = setInterval(function() {
recTime = recTime + 1;
setAudioPosition(recTime + " sec");
- if (recTime >= 10) {
+ if (recTime >= 6) {
clearInterval(recInterval);
mediaRec.stopRecord();
+ mediaRec.release();
+ playAudio(src);
}
}, 1000);
}
+ function playAudio(src) {
+ // Create Media object from src
+ my_media = new Media(src, onSuccess, onError);
+
+ // Play audio
+ my_media.play();
+ // Update media position every second
+ mediaTimer = setInterval(function() {
+ // get media position
+ my_media.getCurrentPosition(
+ // success callback
+ function(position) {
+ if (position > -1) {
+ setAudioPosition(position + " sec");
+ }
+ if (position > 4) {
+ clearInterval(mediaTimer);
+ mediaTimer.stop();
+ mediaTimer.release();
+ alert('all done');
+ }
+ },
+ // error callback
+ function(e) {
+ alert("Error getting pos=" + e);
+ my_media.release();
+ }
+ );
+ }, 500);
+ }
+
// PhoneGap is ready
//
function onDeviceReady() {
@@ -41,7 +74,7 @@
// onSuccess Callback
//
function onSuccess() {
- console.log("recordAudio():Audio Success");
+ alert('Success');
}
// onError Callback
@@ -62,5 +95,6 @@
<body>
<p id="media">Recording audio...</p>
<p id="audio_position"></p>
+ <div><a href="index.html">Back</a></div>
</body>
</html>
View
39 audio2.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Capture Audio</title>
+
+ <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
+ <script type="text/javascript" charset="utf-8" src="json2.js"></script>
+ <script type="text/javascript" charset="utf-8">
+
+ // Called when capture operation is finished
+ //
+ function captureSuccess(mediaFiles) {
+ var i, len;
+ for (i = 0, len = mediaFiles.length; i < len; i += 1) {
+ alert('path='+mediaFiles[i].fullPath+' name='+mediaFiles[i].name);
+ }
+ }
+
+ // Called if something bad happens.
+ //
+ function captureError(error) {
+ var msg = 'An error occurred during capture: ' + error.code;
+ navigator.notification.alert(msg, null, 'Uh oh!');
+ }
+
+ // A button will call this function
+ //
+ function captureAudio() {
+ // Launch device audio recording application,
+ // allowing user to capture up to 2 audio clips
+ navigator.device.capture.captureAudio(captureSuccess, captureError, {limit: 2});
+ }
+
+ </script>
+ </head>
+ <body>
+ <button onclick="captureAudio();">Capture Audio</button> <br>
+ </body>
+</html>
View
6 index.html
@@ -27,7 +27,9 @@
<div id="welcome" class="view">
<div class="app_button" id="map_button">Show My Location</div>
- <div class="app_button" id="settings_button">Settings</div>
+ <div class="app_button" id="settings_button">Settings</div>
+ <div class="app_button"><a href="audio.html">Audio 1</a></div>
+ <div class="app_button"><a href="audio2.html">Audio 2</a></div>
</div>
<div id="map" class="view">
@@ -60,4 +62,4 @@
</div>
</body>
-</html>
+</html>

0 comments on commit c32c8a1

Please sign in to comment.
Something went wrong with that request. Please try again.