2013-01-21 12 views
7

पर फ़ाइल न करने के लिए मैं एंड्रॉइड.media.MediaRecorder चाहता हूं। ऑडियो को फ़ाइल में नहीं रिकॉर्ड करने के लिए, लेकिन उसी चर में, उदाहरण के लिए char [] या बाइट [] या कुछ अन्य दत्ता बफर संरचना। मैं इसे वाई-फाई के माध्यम से रिमोट सर्वर पर भेजना चाहता हूं, android.media.MediaRecorder यह कार्यक्षमता प्रदान कर सकता है?रिकॉर्डिंग ऑडियो एंड्रॉइड

+0

यह संभव है पर लिखेंगे लिखने के लिए डेटा है। MediaRecorder एक फ़ाइलडिस्क्रिप्टर को एक फाइल के लिए जरूरी नहीं लिखता है। ध्यान दें कि यह "स्ट्रीमिंग" नहीं है! आपको सर्वर-साइड पर एक फाइल को फिर से लिखना होगा। इससे मदद मिल सकती है: http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system – Fildor

+0

असल में आप एक फ़ाइल डिस्क्रिप्टर बना सकते हैं जो बस लिखता है फ़ाइल के बजाय एक आंतरिक बफर के लिए, यह भी न भूलें कि सॉकेट में फ़ाइल डिस्क्रिप्टर भी है, जिसे आप सॉकेट में लिखने के लिए लिखते हैं। फ़ाइल सर्वर को लिखने की कोई आवश्यकता नहीं है जब तक कि उन पैकेट प्राप्त करने के लिए सही सॉकेट पते पर कुछ सुन रहा हो और तदनुसार उन्हें संसाधित करें। –

उत्तर

14

आप यहां क्या कर सकते हैं ParcelFileDescriptor क्लास का उपयोग कर सकते हैं।

//make a pipe containing a read and a write parcelfd 
ParcelFileDescriptor[] fdPair = ParcelFileDescriptor.createPipe(); 

//get a handle to your read and write fd objects. 
ParcelFileDescriptor readFD = fdPair[0]; 
ParcelFileDescriptor writeFD = fdPair[1]; 

//next set your mediaRecorder instance to output to the write side of this pipe. 
mediaRecorder.setOutputFile(writeFD.getFileDescriptor()); 

//next create an input stream to read from the read side of the pipe. 
FileInputStream reader = new FileInputStream(readFD.getFileDescriptor()); 

//now to fill up a buffer with data, we just do a simple read 
byte[] buffer = new byte[4096];//or w/e buffer size you want 

//fill up your buffer with data from the stream 
reader.read(buffer);// may want to do this in a separate thread 

और अब आप एक बफर ऑडियो डेटा का पूरा

वैकल्पिक रूप से है, तो आप डेटा रिकॉर्डर से एक सॉकेट के लिए सीधे लिखने के लिए कर सकते हैं। यह ParcelFileDescriptor कक्षा के साथ भी हासिल किया जा सकता है।

//create a socket connection to another device 
Socket socket = new Socket("123.123.123.123",65535);//or w/e socket address you are using 

//wrap the socket with a parcel so you can get at its underlying File descriptor 
ParcelFileDescriptor socketWrapper = ParcelFileDescriptor.fromSocket(socket); 

//set your mediaRecorder instance to write to this file descriptor 
mediaRecorder.setOutputFile(socketWrapper.getFileDescriptor()); 

अब किसी भी समय अपने मीडिया रिकॉर्डर यह स्वचालित रूप से सॉकेट

संबंधित मुद्दे