2013-12-10 202 views
2

如何從如何播放音頻或視頻ParcelFileDescriptor

ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket); 
mp.setDataSource(pfd.getFileDescriptor()); 
pfd.close(); 
mp.setDisplay(holder); 
mp.prepareAsync(); 
mp.start(); 

其示值誤差播放視頻或音頻是無法創建媒體player.what我有什麼關係?

回答

0

我不確定你真的想要什麼但可能是this答案可以幫到你。 也讀了原來的問題,以確保它是你有同樣的問題。

試試這個代碼:

String hostname = "192.168.1.10"; 
int port = 8000; 
Socket socket = null; 
    try { 
     socket = new Socket(InetAddress.getByName(hostname), port); 
    } catch (UnknownHostException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket); 

recorder = new MediaRecorder(); 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setOutputFile(pfd.getFileDescriptor()); 

    try { 
     recorder.prepare(); 
    } catch (IllegalStateException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

recorder.start(); 
+0

雅我正在使用包裹文件描述符發送音頻文件到服務器端,但我再也能夠通過使用包裹文件描述符笏的原因玩? – Aravi

+0

這段代碼適合你嗎? – Val

+0

沒有它沒有工作... – Aravi