File tree Expand file tree Collapse file tree
src/main/java/com/github/squi2rel/vp Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020import org .slf4j .Logger ;
2121import org .slf4j .LoggerFactory ;
2222
23+ import java .util .concurrent .Executors ;
24+ import java .util .concurrent .ScheduledExecutorService ;
25+
2326public class VideoPlayerMain implements ModInitializer {
2427 public static final String MOD_ID = "videoplayer" ;
2528 public static final String version = FabricLoader .getInstance ().getModContainer (MOD_ID ).orElseThrow ().getMetadata ().getVersion ().toString ();
2629 public static Throwable error = null ;
2730
2831 public static final Logger LOGGER = LoggerFactory .getLogger (MOD_ID );
2932
33+ public static ScheduledExecutorService scheduler = Executors .newScheduledThreadPool (1 , VideoPlayerMain ::newDaemon );
34+
3035 @ SuppressWarnings ("resource" )
3136 @ Override
3237 public void onInitialize () {
@@ -60,4 +65,10 @@ public void onInitialize() {
6065 return 1 ;
6166 }))));
6267 }
68+
69+ private static Thread newDaemon (Runnable task ) {
70+ Thread t = new Thread (task );
71+ t .setDaemon (true );
72+ return t ;
73+ }
6374}
Original file line number Diff line number Diff line change 11package com .github .squi2rel .vp .video ;
22
33import com .github .squi2rel .vp .DataHolder ;
4+ import com .github .squi2rel .vp .VideoPlayerMain ;
45import com .github .squi2rel .vp .network .ByteBufUtils ;
56import com .github .squi2rel .vp .network .ServerPacketHandler ;
67import com .github .squi2rel .vp .provider .NamedProviderSource ;
1213
1314import java .util .*;
1415import java .util .concurrent .CompletableFuture ;
16+ import java .util .concurrent .TimeUnit ;
1517import java .util .concurrent .locks .ReentrantLock ;
1618
1719import static com .github .squi2rel .vp .DataHolder .server ;
@@ -196,12 +198,12 @@ public synchronized void playNext() {
196198 if (s == null ) return ;
197199 synchronized (this ) {
198200 nextTask = null ;
199- s .stopped (() -> {
201+ s .stopped (() -> VideoPlayerMain . scheduler . schedule (() -> {
200202 lock ();
201203 infos .poll ();
202204 unlock ();
203205 playNext ();
204- });
206+ }, 2 , TimeUnit . SECONDS ) );
205207 s .listen ();
206208 }
207209 });
You can’t perform that action at this time.
0 commit comments