浏览代码

bugfix when not being able to read all samples

ncannasse 10 年之前
父节点
当前提交
1136eb4a5d
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13 1
      hxd/snd/Mp3Data.hx

+ 13 - 1
hxd/snd/Mp3Data.hx

@@ -65,7 +65,19 @@ class Mp3Data extends Data {
 		#if flash
 		var b = out.getData();
 		b.position = outPos;
-		snd.extract(b, sampleCount, sampleStart + 2257 /* MAGIC_DELAY, silence added at mp3 start */ );
+		while( sampleCount > 0 ) {
+			var r = Std.int(snd.extract(b, sampleCount, sampleStart + 2257 /* MAGIC_DELAY, silence added at mp3 start */ ));
+			if( r == 0 ) {
+				while( sampleCount > 0 ) {
+					b.writeFloat(0);
+					b.writeFloat(0);
+					sampleCount--;
+				}
+				return;
+			}
+			sampleCount -= r;
+			sampleStart += r;
+		}
 		#elseif js
 		if( buffer == null ) {
 			// not yet available : fill with blanks