Skip to content

Commit

Permalink
enforce playing status when frame is loading
Browse files Browse the repository at this point in the history
  • Loading branch information
SrRapero720 committed Jul 27, 2023
1 parent 2aa7134 commit ae1c57d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public IDisplay requestDisplay() {
}
if (display != null) return display;

return display = cache.createDisplay(new Vec3d(worldPosition), url, volume, minDistance, maxDistance, loop);
return display = cache.createDisplay(new Vec3d(worldPosition), url, volume, minDistance, maxDistance, loop, playing);
}

public AlignedBox getBox() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public IDisplay requestDisplay() {
return null;
if (display != null)
return display;
return display = cache.createDisplay(new Vec3d(worldPosition), url, volume, minDistance, maxDistance, loop);
return display = cache.createDisplay(new Vec3d(worldPosition), url, volume, minDistance, maxDistance, loop, playing);
}

public AlignedBox getBox() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public static void unload() {
}
}

public static IDisplay createVideoDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop) {
public static IDisplay createVideoDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop, boolean playing) {
return ThreadUtil.tryAndReturn((defaultVar) -> {
var display = new VideoDisplay(pos, url, volume, minDistance, maxDistance, loop);
if (display.player.getRaw() == null) throw new IllegalStateException("MediaDisplay uses a broken player");
var display = new VideoDisplay(pos, url, volume, minDistance, maxDistance, loop, playing);
if (display.player.raw() == null) throw new IllegalStateException("MediaDisplay uses a broken player");
OPEN_DISPLAYS.add(display);
return display;

Expand All @@ -65,15 +65,15 @@ public static IDisplay createVideoDisplay(Vec3d pos, String url, float volume, f

private final Vec3d pos;
private volatile IntBuffer buffer;
public int texture;
private int texture;
private boolean stream = false;
private float lastSetVolume;
private volatile boolean needsUpdate = false;
private final ReentrantLock lock = new ReentrantLock();
private volatile boolean first = true;
private long lastCorrectedTime = Long.MIN_VALUE;

public VideoDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop) {
public VideoDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop, boolean playing) {
super();
this.pos = pos;
this.texture = GlStateManager._genTexture();
Expand Down Expand Up @@ -106,6 +106,7 @@ public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
lastSetVolume = getVolume(volume, minDistance, maxDistance);
player.setVolume((int) lastSetVolume);
player.setRepeatMode(loop);
player.setPauseMode(!playing);
player.start(url);
}

Expand Down Expand Up @@ -140,8 +141,8 @@ public void tick(String url, float volume, float minDistance, float maxDistance,
volume = getVolume(volume, minDistance, maxDistance);
if (volume != lastSetVolume) {
// ENSURE PLAYER GET MUTED ON LONG DISTANCES
if (volume < 0.1) player.getRaw().mediaPlayer().audio().setMute(true);
if (volume >= 0.1) player.getRaw().mediaPlayer().audio().setMute(false);
if (volume < 0.1) player.setMuteMode(true);
if (volume >= 0.1) player.setMuteMode(false);

player.setVolume((int) volume);
lastSetVolume = volume;
Expand All @@ -150,8 +151,7 @@ public void tick(String url, float volume, float minDistance, float maxDistance,
if (player.isValid()) {
boolean realPlaying = playing && !Minecraft.getInstance().isPaused();

if (player.getRepeatMode() != loop)
player.setRepeatMode(loop);
if (player.getRepeatMode() != loop) player.setRepeatMode(loop);
long tickTime = 50;
long newDuration = player.getDuration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import me.srrapero720.waterframes.display.IDisplay;
import me.srrapero720.waterframes.display.ImageDisplay;
import me.srrapero720.waterframes.display.VideoDisplay;
import me.srrapero720.watermedia.Util;
import me.srrapero720.watermedia.api.WaterMediaAPI;
import me.srrapero720.watermedia.api.images.PictureFetcher;
import me.srrapero720.watermedia.api.images.RenderablePicture;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -51,13 +53,13 @@ private synchronized void attemptToLoad() {
}
}

public IDisplay createDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop) {
return createDisplay(pos, url, volume, minDistance, maxDistance, loop, false);
public IDisplay createDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop, boolean playing) {
return createDisplay(pos, url, volume, minDistance, maxDistance, loop, playing, false);
}

public IDisplay createDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop, boolean noVideo) {
public IDisplay createDisplay(Vec3d pos, String url, float volume, float minDistance, float maxDistance, boolean loop, boolean playing, boolean noVideo) {
volume *= Minecraft.getInstance().options.getSoundSourceVolume(SoundSource.MASTER);
if (picture == null && !noVideo && !WFConfig.isDisabledVLC()) return VideoDisplay.createVideoDisplay(pos, url, volume, minDistance, maxDistance, loop);
if (picture == null && !noVideo && !WFConfig.isDisabledVLC()) return VideoDisplay.createVideoDisplay(pos, url, volume, minDistance, maxDistance, loop, playing);

return new ImageDisplay(picture) {
@Override
Expand Down

0 comments on commit ae1c57d

Please sign in to comment.