Any Android module devs out there want to help me solve a problem? (That everyone could benefit from)
Hello,
I need help.
You might have seen the demo on the Dev Blog a while ago showing how to use Activity Intents to record audio on Android. (Yes, yes, I know about the Codeboxed module.. that's not the point ;) )
Here's the post:
http://developer.appcelerator.com/blog/2011/02/launching-activities-and-using-content-uris-in-android.html/comment-page-1#comment-67235
The issue I have with the demo is that the recorder returns a 'contentUri' to the recorded file. This is actually a reference to the file which is stored in the internal database in the device. This, as you may discover, is pretty useless when it comes to wanting to upload it or save it somewhere, for exmaple, since Ti.Filesystem just can't get a handle on it.
The actual path to the audio in the database is in a field called "_data" as far as I can tell.
So, (as Don Thorpe suggested in the comments on the blog post about this) all we need to do is create a simple module that can query the Media database of the file based on the contentUri and return the full file path.
Now, I'm no Java programmer at all (that's why we use Titanium right? ;) ) but I know some of you are. I have had a dabble in trying to get this working though, and I've made some progress, I think!!
But, it's not working, and I know I must be missing something obvious (to those of you with a firmer grip on Java and how Titanium/Kroll uses it)
Here's a link to a Gist to see the java code I'm come up with so far, and also the javascript I'm using to call it.
https://gist.github.com/1152360
Here's a link to the JavaScript I'm using to test it (based o nthe blog post exmaple)
https://gist.github.com/1152362
Here's the error I'm getting : I must be doing some wrong with understanding maybe how proxies work? I don't know.. ;/
https://gist.github.com/1152370
If anyone could help get this sorted, I think it would help make a great tutorial/exmaple on how to go about building these things. From what I've learned so far while struggling for the past few days on this, it looks as if a better understanding could really pay dividends when it comes to extending Ti with modules.
Cheers!
:)
4 Answers
-
OK. I'm going to answer my own question, since after hacking around at this ALL DAY (I'm not even a Java programmer) I managed to get it working.
Here's some Java module code which works (I haven't built out the full app exmaple yet, but I'll do that in due course).
https://gist.github.com/1153138
Hey, go me! ;)
-
Hey Kosso, you code that java class?
-
Hi Kosso,
Did you want something different from the audio recorder? were you missing some features, that made you go with the intent driven one? Just curious, because we are in the process of updating it and your input would help.
I am really glad that you fixed the problem.
Alex
-
Hi Kosso,
I am currently working on a Video Recording module, its not easy, but it will be cool and i think it will help a lot of people.
About the audio recording. We are updating that module and offer support for recording raw audio and high bitrate audio, basically its being rebuilt from the ground app. We received a lot of suggestions among which the exact same thing that you are saying, "audio quality", so we are putting a lot of effort into delivering a high end module with high quality audio recordings.
I will be glad to send you a pre-release version to test it out. I will DM you on twitter when i have something ready.
Thank you.
Alex