|
var win = Ti.UI.createWindow({ |
|
title: 'Sound Recorder Test', |
|
exitOnClose: true, |
|
fullscreen: false, |
|
backgroundColor: 'black' |
|
}); |
|
|
|
// const value grabbed from |
|
// http://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html#RECORD_SOUND_ACTION |
|
var RECORD_SOUND_ACTION = "android.provider.MediaStore.RECORD_SOUND"; |
|
var soundUri = null; // Will be set as a result of recording action. |
|
|
|
var recordButton = Titanium.UI.createButton({ |
|
top: 10, left: 10, right: 10, height: 35, title: "Record Audio" |
|
}); |
|
var labelResultCaption = Titanium.UI.createLabel({ |
|
top: 50, left: 10, right: 10, height: 35, visible: false, color: 'yellow' |
|
}); |
|
var labelResult = Titanium.UI.createLabel({ |
|
top: 90, left: 10, right: 10, height: 100, visible: false, |
|
backgroundColor: 'white', color: 'black', |
|
verticalAlign: 'top' |
|
}); |
|
|
|
var sendButton = Titanium.UI.createButton({ |
|
top: 200, left: 10, right: 10, height: 35, |
|
title: "Share Recorded Audio", visible: false |
|
}); |
|
sendButton.addEventListener('click', function(){ |
|
var intent = Titanium.Android.createIntent({ |
|
action: Titanium.Android.ACTION_SEND, |
|
type: 'audio/amr' |
|
}); |
|
intent.putExtraUri(Titanium.Android.EXTRA_STREAM, soundUri); |
|
Titanium.Android.currentActivity.startActivity(intent); |
|
}); |
|
|
|
recordButton.addEventListener('click', function() { |
|
var intent = Titanium.Android.createIntent({ action: RECORD_SOUND_ACTION }); |
|
Titanium.Android.currentActivity.startActivityForResult(intent, function(e) { |
|
if (e.error) { |
|
labelResultCaption.text = 'Error: ' + e.error; |
|
labelResultCaption.visible = true; |
|
} else { |
|
if (e.resultCode === Titanium.Android.RESULT_OK) { |
|
soundUri = e.intent.data; |
|
labelResultCaption.text = 'Audio Captured. Content URI:'; |
|
labelResult.text = soundUri; |
|
labelResultCaption.visible = true; |
|
labelResult.visible = true; |
|
sendButton.visible = true; |
|
} else { |
|
labelResultCaption.text = 'Canceled/Error? Result code: ' + e.resultCode; |
|
labelResultCaption.visible = true; |
|
} |
|
} |
|
}); |
|
}); |
|
|
|
win.add(recordButton); |
|
win.add(labelResultCaption); |
|
win.add(labelResult); |
|
win.add(sendButton); |
|
win.open(); |
How we can implement Pause in this application?