2017-04-20 116 views
0

我阅读了大量的代码读取字节从WAV了解Android Studio如何从WAV字节在Android Studio中

,但我仍然无法从WAV得到字节

真正需要的代码或演示,所以我可以得到了什么,我需要

什么错我的代码

Resources inn = getResources(); 
    InputStream in = inn.openRawResource(R.raw.ccheer); 
    BufferedInputStream bis = new BufferedInputStream(in, 8000); 
    DataInputStream dis = new DataInputStream(bis); 
    byte[] music = null; 
    music = new byte[1024]; 
    int i = 0; 
    try { 
     while (dis.available() > 0) { 

      music[i]=dis.readByte(); 
      i++; 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 


} 
+0

什么,当你运行发生这种情况?它是否遇到异常?什么是异常消息? – criticalfix

+0

这里是答案[使用此答案](http://stackoverflow.com/a/15098868/6619302) –

+0

你想读取数据作为音频?你想要计算音频帧的数量吗? Android是否使用Java的AudioInputStream和AudioFormat类? –

回答

0

这里是我的新代码。仍然无法读取字节[]

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == PICK_AUDIO_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { 
     Uri uri = data.getData(); 
     System.out.println("Uri: " + uri); 
     InputStream is = new FileInputStream(getRealPathFromURI(this,uri)); 

    } 

} 

public static byte[] convertStreamToByteArray(InputStream is) throws IOException { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    byte buffer[] = new byte[1024]; 
    int length = 0; 
    while ((length = is.read(buffer)) != -1) { 
     baos.write(buffer, 0, length); 
    } 
    return baos.toByteArray(); 
} 

最新错?只是想这样写的或其他方式......

字节00

字节11

字节22 ...

相关问题