diff --git a/CHANGELOG.md b/CHANGELOG.md index 5697e4689..868787491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ All notable changes to this project will be documented in this file. - #1303 garbled text when exporting frame with text - #1314 user interface: button order - Internal viewer shows red image when bitmap fill is not available (see issue #1320) +- #1323 Audio playback fails ## [9.0.0] - 2016-08-12 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java index 0910364fb..7aa8cefcf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java @@ -160,11 +160,13 @@ public class SoundExporter { } else { List soundData = st.getRawSoundData(); SWF swf = ((Tag) st).getSwf(); - List 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); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java index ca689c815..7d770b8de 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/SoundStreamHeadTag.java @@ -228,12 +228,14 @@ public class SoundStreamHeadTag extends Tag implements SoundStreamHeadTypeTag { public List getRawSoundData() { List ret = new ArrayList<>(); List 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; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java index 053e0623e..d5e6e19d5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/sound/SoundFormat.java @@ -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 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; diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 86731957e..e81e7394e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -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) { diff --git a/src/com/jpexs/decompiler/flash/gui/SoundTagPlayer.java b/src/com/jpexs/decompiler/flash/gui/SoundTagPlayer.java index d11bc769b..e03068a0b 100644 --- a/src/com/jpexs/decompiler/flash/gui/SoundTagPlayer.java +++ b/src/com/jpexs/decompiler/flash/gui/SoundTagPlayer.java @@ -94,7 +94,6 @@ public class SoundTagPlayer implements MediaDisplay { this.loopCount = loops; clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class)); clip.addLineListener(new LineListener() { - @Override public void update(LineEvent event) { if (event.getType() == LineEvent.Type.STOP) { @@ -123,7 +122,6 @@ public class SoundTagPlayer implements MediaDisplay { timer = new Timer(); timer.schedule(new TimerTask() { - @Override public void run() { @@ -141,7 +139,6 @@ public class SoundTagPlayer implements MediaDisplay { openSound(tag); } else { new Thread() { - @Override public void run() { try { @@ -155,7 +152,6 @@ public class SoundTagPlayer implements MediaDisplay { } } } - }.start(); } } @@ -166,14 +162,13 @@ public class SoundTagPlayer implements MediaDisplay { if (wavData == null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); List soundData = tag.getRawSoundData(); - List siss = new ArrayList<>(); for (ByteArrayRange data : soundData) { - SWFInputStream sis = new SWFInputStream(swf, data.getArray(), 0, data.getPos() + data.getLength()); - sis.seek(data.getPos()); - siss.add(sis); + baos.write(data.getArray(), data.getPos(), data.getLength()); } - tag.getSoundFormat().createWav(siss, baos); + SWFInputStream sis = new SWFInputStream(swf, baos.toByteArray()); + baos = new ByteArrayOutputStream(); + tag.getSoundFormat().createWav(sis, baos); wavData = baos.toByteArray(); swf.putToCache(tag, wavData); }