Fixed: Flash viewer - Sound envelope handling

This commit is contained in:
Jindra Petřík
2021-03-23 22:41:19 +01:00
parent efdcb27963
commit 9a45708ebb
17 changed files with 313 additions and 52 deletions

View File

@@ -2039,7 +2039,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
loopCount = Math.max(1, soundInfo.loopCount);
}
sp = new SoundTagPlayer(st, loopCount, false);
sp = new SoundTagPlayer(soundInfo, st, loopCount, false);
sp.addEventListener(new MediaDisplayListener() {
@Override
public void mediaDisplayStateChanged(MediaDisplay source) {

View File

@@ -3606,7 +3606,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
previewPanel.showImagePanel(new SerializableImage(View.loadImage("sound32")));
previewPanel.setImageReplaceButtonVisible(((Tag) treeItem).isReadOnly() && (treeItem instanceof DefineSoundTag), false);
try {
SoundTagPlayer soundThread = new SoundTagPlayer((SoundTag) treeItem, Configuration.loopMedia.get() ? Integer.MAX_VALUE : 1, true);
SoundTagPlayer soundThread = new SoundTagPlayer(null, (SoundTag) treeItem, Configuration.loopMedia.get() ? Integer.MAX_VALUE : 1, true);
previewPanel.setMedia(soundThread);
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException ex) {
logger.log(Level.SEVERE, null, ex);

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.gui.player.MediaDisplayListener;
import com.jpexs.decompiler.flash.gui.player.Zoom;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.types.SOUNDINFO;
import com.jpexs.helpers.ByteArrayRange;
import java.awt.Color;
import java.awt.image.BufferedImage;
@@ -88,7 +89,7 @@ public class SoundTagPlayer implements MediaDisplay {
private static final int FRAME_DIVISOR = 8000;
public SoundTagPlayer(final SoundTag tag, int loops, boolean async) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
public SoundTagPlayer(final SOUNDINFO soundInfo, final SoundTag tag, int loops, boolean async) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
this.tag = tag;
this.loopCount = loops;
clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
@@ -135,13 +136,13 @@ public class SoundTagPlayer implements MediaDisplay {
if (!async) {
paused = true;
openSound(tag);
openSound(soundInfo, tag);
} else {
new Thread() {
@Override
public void run() {
try {
openSound(tag);
openSound(soundInfo, tag);
} catch (IOException | LineUnavailableException | UnsupportedAudioFileException ex) {
Logger.getLogger(SoundTagPlayer.class.getName()).log(Level.SEVERE, null, ex);
}
@@ -155,15 +156,15 @@ public class SoundTagPlayer implements MediaDisplay {
}
}
private void openSound(SoundTag tag) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
private void openSound(SOUNDINFO soundInfo, SoundTag tag) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
SWF swf = ((Tag) tag).getSwf();
byte[] wavData = swf.getFromCache(tag);
byte[] wavData = swf.getFromCache(soundInfo, tag);
if (wavData == null) {
List<ByteArrayRange> soundData = tag.getRawSoundData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tag.getSoundFormat().createWav(soundData, baos);
tag.getSoundFormat().createWav(soundInfo, soundData, baos);
wavData = baos.toByteArray();
swf.putToCache(tag, wavData);
swf.putToCache(soundInfo, tag, wavData);
}
synchronized (playLock) {