#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

@@ -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

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) {

View File

@@ -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<ByteArrayRange> soundData = tag.getRawSoundData();
List<SWFInputStream> 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);
}