Merge branch 'master' of git://github.com/Indeed/phonegap into phonegap2

Conflicts:
	android/assets/gap.js
	android/assets/index.html
	android/bin/DroidGap.apk
	android/bin/classes.dex
	android/bin/com/nitobi/phonegap/PhoneGap$1.class
	android/bin/com/nitobi/phonegap/PhoneGap$2.class
	android/bin/com/nitobi/phonegap/PhoneGap.class
	android/bin/resources.ap_
	android/src/com/nitobi/phonegap/PhoneGap.java
This commit is contained in:
addios
2009-02-27 11:47:10 +07:00
23 changed files with 234 additions and 1 deletions
+102
View File
@@ -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; }
}
}
+43
View File
@@ -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));
}
}