diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4aac3e48..a25a88c0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -13,6 +13,7 @@ + diff --git a/assets/gap.js b/assets/gap.js index b15b0923..c7390440 100644 --- a/assets/gap.js +++ b/assets/gap.js @@ -307,6 +307,7 @@ var Device = { window.DroidGap.httpGet(url, file); } }, + storage: { result: "", testSDCard: function(){ @@ -330,6 +331,30 @@ var Device = { return Device.storage.result; } } + + + audio: { + startRecording: function(file) { + window.DroidGap.startRecordingAudio(file); + }, + stopRecording: function() { + window.DroidGap.stopRecordingAudio(); + }, + startPlaying: function(file) { + window.DroidGap.startPlayingAudio(file); + }, + stopPlaying: function() { + window.DroidGap.stopPlayingAudio(); + }, + getCurrentPosition: function() { + return window.DroidGap.getCurrentPositionAudio(); + }, + getDuration: function(file) { + return window.DroidGap.getDurationAudio(file); + } + } + + } function gotLocation(lat, lon) { diff --git a/assets/index.html b/assets/index.html index a5ff8e48..e74ab1c8 100644 --- a/assets/index.html +++ b/assets/index.html @@ -105,9 +105,10 @@ function onReceiveSms(number, message) http = function(func) { if (func == 'get') { - Device.http.get($('httpGetUrl').value, $('httpGetFile').value) + Device.http.get($('httpGetUrl').value, $('httpGetFile').value); } } + fileManagement = function(x){ if (x == 'testSDCard'){ $('file_status').value = Device.storage.testSDCard(); @@ -125,6 +126,31 @@ fileManagement = function(x){ $('file_status').value = Device.storage.delDir($('deldir').value); } } +======= + +audio = function(func) +{ + if (func == 'startPlaying') { + Device.audio.startPlaying($('audioFile').value); + } else + if (func == 'stopPlaying') { + Device.audio.stopPlaying(); + } else + if (func == 'startRecording') { + Device.audio.startRecording($('audioFile').value); + } else + if (func == 'stopRecording') { + Device.audio.stopRecording(); + } else + if (func == 'getCurrentPosition') { + $('posdur').value = Device.audio.getCurrentPosition(); + } else + if (func == 'getDuration') { + $('posdur').value = Device.audio.getDuration($('audioFile').value); + } +} + + addLoadEvent(initGap); @@ -146,6 +172,7 @@ addLoadEvent(initGap);
  • Vibration
  • Play Sound
  • Photo...
  • +
  • Audio...
  • Notification...
  • HTTP...
  • External Storage
  • @@ -333,4 +360,39 @@ addLoadEvent(initGap); +
    +

    Audio

    +
    +
    + + +
    +
    +
    + +
    +
    + +
    +
    +
    + + +
    +
    +
    + +
    +
    + +
    diff --git a/bin/com/nitobi/phonegap/AccelTuple.class b/bin/com/nitobi/phonegap/AccelTuple.class deleted file mode 100644 index b023969b..00000000 Binary files a/bin/com/nitobi/phonegap/AccelTuple.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/CameraHandler.class b/bin/com/nitobi/phonegap/CameraHandler.class deleted file mode 100644 index 87db7fad..00000000 Binary files a/bin/com/nitobi/phonegap/CameraHandler.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/CameraListener.class b/bin/com/nitobi/phonegap/CameraListener.class deleted file mode 100644 index fd0cf9be..00000000 Binary files a/bin/com/nitobi/phonegap/CameraListener.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class b/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class deleted file mode 100644 index ad51e474..00000000 Binary files a/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/DroidGap.class b/bin/com/nitobi/phonegap/DroidGap.class deleted file mode 100644 index 132a749e..00000000 Binary files a/bin/com/nitobi/phonegap/DroidGap.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/GeoTuple.class b/bin/com/nitobi/phonegap/GeoTuple.class deleted file mode 100644 index abc64963..00000000 Binary files a/bin/com/nitobi/phonegap/GeoTuple.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/GpsListener.class b/bin/com/nitobi/phonegap/GpsListener.class deleted file mode 100644 index 582bcc94..00000000 Binary files a/bin/com/nitobi/phonegap/GpsListener.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/HttpHandler.class b/bin/com/nitobi/phonegap/HttpHandler.class deleted file mode 100644 index 832e6c93..00000000 Binary files a/bin/com/nitobi/phonegap/HttpHandler.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/NetworkListener.class b/bin/com/nitobi/phonegap/NetworkListener.class deleted file mode 100644 index 1fd9193f..00000000 Binary files a/bin/com/nitobi/phonegap/NetworkListener.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/Orientation.class b/bin/com/nitobi/phonegap/Orientation.class deleted file mode 100644 index a5595ae2..00000000 Binary files a/bin/com/nitobi/phonegap/Orientation.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R$attr.class b/bin/com/nitobi/phonegap/R$attr.class deleted file mode 100644 index 23dc64ed..00000000 Binary files a/bin/com/nitobi/phonegap/R$attr.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R$drawable.class b/bin/com/nitobi/phonegap/R$drawable.class deleted file mode 100644 index 862620ca..00000000 Binary files a/bin/com/nitobi/phonegap/R$drawable.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R$id.class b/bin/com/nitobi/phonegap/R$id.class deleted file mode 100644 index ef630e1a..00000000 Binary files a/bin/com/nitobi/phonegap/R$id.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R$layout.class b/bin/com/nitobi/phonegap/R$layout.class deleted file mode 100644 index 6d977387..00000000 Binary files a/bin/com/nitobi/phonegap/R$layout.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R$raw.class b/bin/com/nitobi/phonegap/R$raw.class deleted file mode 100644 index 21cf9055..00000000 Binary files a/bin/com/nitobi/phonegap/R$raw.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R$string.class b/bin/com/nitobi/phonegap/R$string.class deleted file mode 100644 index 53d84ae2..00000000 Binary files a/bin/com/nitobi/phonegap/R$string.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/R.class b/bin/com/nitobi/phonegap/R.class deleted file mode 100644 index 16bcfcf5..00000000 Binary files a/bin/com/nitobi/phonegap/R.class and /dev/null differ diff --git a/bin/com/nitobi/phonegap/SmsListener.class b/bin/com/nitobi/phonegap/SmsListener.class deleted file mode 100644 index c174d51f..00000000 Binary files a/bin/com/nitobi/phonegap/SmsListener.class and /dev/null differ diff --git a/src/com/nitobi/phonegap/AudioHandler.java b/src/com/nitobi/phonegap/AudioHandler.java new file mode 100644 index 00000000..7a2934bf --- /dev/null +++ b/src/com/nitobi/phonegap/AudioHandler.java @@ -0,0 +1,102 @@ +package com.nitobi.phonegap; + +import java.io.File; + +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.media.MediaPlayer.OnCompletionListener; + +public class AudioHandler implements OnCompletionListener { + private MediaRecorder recorder; + private boolean isRecording = false; + MediaPlayer mPlayer; + private boolean isPlaying = false; + private String recording; + private String saveFile; + + public AudioHandler(String file) { + this.recording = file; + } + + public void startRecording(String file){ + if (!isRecording){ + saveFile=file; + recorder = new MediaRecorder(); + recorder.setAudioSource(MediaRecorder.AudioSource.MIC); + recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + recorder.setOutputFile(this.recording); + recorder.prepare(); + isRecording = true; + recorder.start(); + } + } + + private void moveFile(String file) { + /* this is just a hck that I will remove later */ + File f = new File (this.recording); + f.renameTo(new File("/sdcard" + file)); + System.out.println(this.recording); + System.out.println(file); + } + + public void stopRecording(){ + try{ + if((recorder != null)&&(isRecording)) + { + isRecording = false; + recorder.stop(); + recorder.release(); + } + moveFile(saveFile); + }catch (Exception e){e.printStackTrace();} + } + + public void startPlaying(String file) { + if (isPlaying==false) { + try { + mPlayer = new MediaPlayer(); + isPlaying=true; + mPlayer.setDataSource("/sdcard/" + file); + mPlayer.prepare(); + mPlayer.setOnCompletionListener(this); + mPlayer.start(); + } catch (Exception e) { e.printStackTrace(); } + } + } + + public void stopPlaying() { + if (isPlaying) { + mPlayer.stop(); + mPlayer.release(); + isPlaying=false; + } + } + + public void onCompletion(MediaPlayer mPlayer) { + mPlayer.stop(); + mPlayer.release(); + isPlaying=false; + } + + public long getCurrentPosition() { + if (isPlaying) + { + return(mPlayer.getCurrentPosition()); + } else { return(-1); } + } + + public long getDuration(String file) { + long duration = -2; + if (isPlaying==false) { + try { + mPlayer = new MediaPlayer(); + mPlayer.setDataSource("/sdcard/" + file); + mPlayer.prepare(); + duration = mPlayer.getDuration(); + mPlayer.release(); + } catch (Exception e) { e.printStackTrace(); return(-1); } + return duration; + } else { return -1; } + } +} diff --git a/src/com/nitobi/phonegap/PhoneGap.java b/src/com/nitobi/phonegap/PhoneGap.java index 9918dd89..9a313758 100644 --- a/src/com/nitobi/phonegap/PhoneGap.java +++ b/src/com/nitobi/phonegap/PhoneGap.java @@ -246,6 +246,7 @@ public class PhoneGap{ HttpHandler http = new HttpHandler(); http.get(url, file); } + public String testSaveLocationExists(){ if (fileManager.testSaveLocationExists()) return "SD Card available"; @@ -276,5 +277,47 @@ public class PhoneGap{ else return "Not completed"; } + + + + /** + * AUDIO + * TODO: Basic functions done but needs more work on error handling and call backs, remove record hack + */ + AudioHandler audio = new AudioHandler("/sdcard/tmprecording.mp3"); + public void startRecordingAudio(String file) + { + /* for this to work the recording needs to be specified in the constructor, + * a hack to get around this, I'm moving the recording after it's complete + */ + audio.startRecording(file); + } + + public void stopRecordingAudio() + { + audio.stopRecording(); + } + + public void startPlayingAudio(String file) + { + audio.startPlaying(file); + } + + public void stopPlayingAudio() + { + audio.stopPlaying(); + } + + public long getCurrentPositionAudio() + { + System.out.println(audio.getCurrentPosition()); + return(audio.getCurrentPosition()); + } + + public long getDurationAudio(String file) + { + System.out.println(audio.getDuration(file)); + return(audio.getDuration(file)); + } }