我想从资产流中读取MIDI数据 . 根据Windows,该文件是长度为150字节的MIDI0文件 . 使用此代码,我读取由count测量的150个字节,但输出字符串仅为127.5个字节 .
try {
assetStream = assets.open("MIDI0_7.mid");
int count=0;
do {
byteValue = assetStream.read();
count++;
outputString = outputString + Integer.toHexString(byteValue);
} while (byteValue > -1) ;
Log.d("MUSIC", "Final string " +outputString);
Log.d("MUSIC", "bytes read " +count);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
此读取的HEX数据也与MIDI规范AFAICT不匹配 . 应该读取开放的8个字节
4d 54 68 64 00 00 00 06
但我明白了
4d 54 68 64 00 06
我不能确定我的MIDI文件的保存格式(带有来自Cakewalk SONAR的7个音符的导出测试文件)所以我不确定为什么MIDI不符合标准,但在我能解决之前我需要知道我丢失数据的位置!看到从输出流中删除了一些字节,我做错了什么?
编辑:好的,找到了 . 小于16的字节由Integer.toHexString()作为单个字符返回,而不是0x数字 . 轻松修复 .