I'm trying to create an app which records a short audio clip. It looks like Titanium.Media.AudioRecorder isn't supported on Android, so I thought I could use navigator.getUserMedia in a WebView. The following html records audio in Chrome after granting the page permission, but in a WebView, it does nothing (for the Web, I stubbed Titanium.App.fireEvent and addEventListener, and executed startRecording/stopRecording from the console. In Titanium, I use events on Titanium.app to signal when to startRecording and stopRecording). Is my approach feasible, and is there a better way?
<html> <body> <audio controls autoplay></audio> <script> var onFail = function(e) { console.log('Rejected!', e); }; var onSuccess = function(s) { Titanium.App.fireEvent('roadtags:DONERECORDING', s); stream = s; }; window.URL = window.URL || window.webkitURL; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; var stream; var audio = document.querySelector('audio'); function startRecording() { if (navigator.getUserMedia) { navigator.getUserMedia({audio: true}, onSuccess, onFail); } else { console.log('navigator.getUserMedia not present'); } } function stopRecording() { audio.src = window.URL.createObjectURL(stream); Titanium.App.fireEvent('roadtags:DONERECORDING', window.URL.createObjectURL(stream) ); } Titanium.App.addEventListener('roadtags:STARTRECORDING', function(evt) { startRecording(); }); Titanium.App.addEventListener('roadtags:STOPRECORDING', function(evt) { stopRecording(); }); </script> </body> </html>The WebView in Titanium Studio looks like this (self is a View, gUMhtml is a string containing the html above)
self.webview = Titanium.UI.createWebView({ top: 0, left: 0, width: '100%', height: '100%', data:gUMhtml }); self.add(self.webview);