#1323 Audio playback fails

This commit is contained in:
honfika@gmail.com
2016-12-18 23:31:07 +01:00
parent fba49bb876
commit 2bc3eef8e7
6 changed files with 30 additions and 23 deletions

View File

@@ -160,11 +160,13 @@ public class SoundExporter {
} else {
List<ByteArrayRange> soundData = st.getRawSoundData();
SWF swf = ((Tag) st).getSwf();
List<SWFInputStream> siss = new ArrayList<>();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (ByteArrayRange data : soundData) {
siss.add(new SWFInputStream(swf, data.getRangeData()));
baos.write(data.getArray(), data.getPos(), data.getLength());
}
fmt.createWav(siss, fos);
SWFInputStream sis = new SWFInputStream(swf, baos.toByteArray());
fmt.createWav(sis, fos);
}
}
}

View File

@@ -228,12 +228,14 @@ public class SoundStreamHeadTag extends Tag implements SoundStreamHeadTypeTag {
public List<ByteArrayRange> getRawSoundData() {
List<ByteArrayRange> ret = new ArrayList<>();
List<SoundStreamBlockTag> blocks = getBlocks();
for (SoundStreamBlockTag block : blocks) {
ByteArrayRange data = block.streamSoundData;
if (streamSoundCompression == SoundFormat.FORMAT_MP3) {
ret.add(data.getSubRange(4, data.getLength() - 4));
} else {
ret.add(data);
if (blocks != null) {
for (SoundStreamBlockTag block : blocks) {
ByteArrayRange data = block.streamSoundData;
if (streamSoundCompression == SoundFormat.FORMAT_MP3) {
ret.add(data.getSubRange(4, data.getLength() - 4));
} else {
ret.add(data);
}
}
}
return ret;

View File

@@ -21,7 +21,6 @@ import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
@@ -198,12 +197,10 @@ public class SoundFormat {
}
}
public boolean createWav(List<SWFInputStream> siss, OutputStream os) {
public boolean createWav(SWFInputStream sis, OutputStream os) {
ensureFormat();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (SWFInputStream sis : siss) {
decode(sis, baos);
}
decode(sis, baos);
try {
createWavFromPcmData(os, samplingRate, true, stereo, baos.toByteArray());
return true;

View File

@@ -746,6 +746,16 @@ public class Helper {
}
}
public static void appendFile(String file, byte[]... data) {
try (FileOutputStream fos = new FileOutputStream(file, true)) {
for (byte[] d : data) {
fos.write(d);
}
} catch (IOException ex) {
// ignore
}
}
public static void writeFile(String file, byte[]... data) {
try (FileOutputStream fos = new FileOutputStream(file)) {
for (byte[] d : data) {