Created
August 17, 2011 19:16
-
-
Save kosso/1152362 to your computer and use it in GitHub Desktop.
Ti JS code to test the mediaquery module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kosso : 2012 | |
// mediaquery module code is here : https://gist.github.com/1153138 | |
var win = Ti.UI.currentWindow; | |
// 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 | |
}); | |
win.add(recordButton); | |
win.add(labelResultCaption); | |
win.add(labelResult); | |
win.add(sendButton); | |
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() { | |
// Ti.API.debug('DEBUG'); | |
// Ti.API.info('INFO'); | |
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) { | |
Ti.API.debug('###############RESULT_OK######## e : '+e); | |
soundUri = e.intent.data; | |
// THIS DOESN'T WORK | |
// var soundFile = Ti.Filesystem.getFile(soundUri); | |
// So we need to try and create a module to query the internal database based on the contentUrl. | |
// We need to get a field called "_data" which contains the full path to the new audio file. | |
// this is the Ti.Activity | |
var activity = e.source; | |
// Try and send the activity and the soundUri to the module... | |
var pathQuery = require('com.kosso.mediaquery'); | |
Ti.API.info('>>>>>>>>>>>>>>>>>>>>>> QUERY NOW <<<<<<<<<<<<<<<<<<<<<<<'); | |
var thePath = pathQuery.getDataPath(e.source, e.intent.data); | |
Ti.API.info('>> THE PATH IS : '+thePath); | |
Ti.API.info('>>>>>>>>>>>>>>>>>>>>>> QUERY END <<<<<<<<<<<<<<<<<<<<<<<'); | |
// I did this just to be able to see the bit I want amongst all the debug logs... | |
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.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment