mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
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:
commit
3d9fdef7d3
@ -13,6 +13,7 @@
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||
android:debuggable="true">
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
<li><a href="#vibration" onclick="Device.vibrate();">Vibration</a></li>
|
||||
<li><a href="#vibration" onclick="Device.playSound('on.mp3")">Play Sound</a></li>
|
||||
<li><a href="#photo" onclick="Device.Image.getFromPhotoLibrary();">Photo...</a></li>
|
||||
<li><a href="#audio" onclick="audio();">Audio...</a></li>
|
||||
<li><a href="#notification" onclick="notification();">Notification...</a></li>
|
||||
<li><a href="#http" onclick="http();">HTTP...</a></li>
|
||||
<li><a href="#esm" onclick="">External Storage</a></li>
|
||||
@ -333,4 +360,39 @@ addLoadEvent(initGap);
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div id="audio" title="audio" class="panel">
|
||||
<h2>Audio</h2>
|
||||
<fieldset>
|
||||
<div class="row">
|
||||
<label>AudioFile:</label>
|
||||
<input type=text name="audioFile" id="audioFile" size=60 maxlength=2048 value="/hullophonegap.mp3" style="width: 30ex"></input>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="audio('startRecording');">startRecording</a>
|
||||
<a class="button blueButton" type="submit" onclick="audio('stopRecording');">stopRecording</a>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="audio('startPlaying');">startPlaying</a>
|
||||
<a class="button blueButton" type="submit" onclick="audio('stopPlaying');">stopPlaying</a>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div class="row">
|
||||
<label>info:</label>
|
||||
<input disabled="enabled" id="posdur" type="text" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="audio('getDuration');">getDuration</a>
|
||||
<a class="button blueButton" type="submit" onclick="audio('getCurrentPosition');">getPosition</a>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="preloader"></div></body></html>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
102
src/com/nitobi/phonegap/AudioHandler.java
Normal file
102
src/com/nitobi/phonegap/AudioHandler.java
Normal 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; }
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user