1- package xyz .gianlu .librespot .player ;
1+ package xyz .gianlu .librespot .player . feeders . storage ;
22
33import com .google .protobuf .ByteString ;
44import org .apache .log4j .Logger ;
88import xyz .gianlu .librespot .common .Utils ;
99import xyz .gianlu .librespot .common .proto .Metadata ;
1010import xyz .gianlu .librespot .core .Session ;
11+ import xyz .gianlu .librespot .player .AbsChunckedInputStream ;
12+ import xyz .gianlu .librespot .player .GeneralAudioStream ;
1113import xyz .gianlu .librespot .player .codecs .SuperAudioFormat ;
1214import xyz .gianlu .librespot .player .decrypt .AesAudioDecrypt ;
1315import xyz .gianlu .librespot .player .decrypt .AudioDecrypt ;
2022import java .util .concurrent .ExecutorService ;
2123import java .util .concurrent .Executors ;
2224
23- import static xyz .gianlu .librespot .player .ChannelManager .CHUNK_SIZE ;
25+ import static xyz .gianlu .librespot .player .feeders . storage . ChannelManager .CHUNK_SIZE ;
2426
2527/**
2628 * @author Gianlu
@@ -58,12 +60,17 @@ public InputStream stream() {
5860 return chunksBuffer .stream ();
5961 }
6062
61- private void requestChunk (@ NotNull ByteString fileId , int index , @ NotNull AudioFile file ) {
63+ private void requestChunk (@ NotNull ByteString fileId , int index , @ NotNull AudioFile file , boolean retried ) {
6264 if (cacheHandler == null || !tryCacheChunk (index )) {
6365 try {
6466 session .channel ().requestChunk (fileId , index , file );
6567 } catch (IOException ex ) {
66- LOGGER .fatal (String .format ("Failed requesting chunk from network, index: %d" , index ), ex );
68+ LOGGER .fatal (String .format ("Failed requesting chunk from network, index: %d, retried: %b" , index , retried ), ex );
69+ if (retried ) {
70+ // TODO: Fatal
71+ } else {
72+ requestChunk (fileId , index , file , true );
73+ }
6774 }
6875 }
6976 }
@@ -98,7 +105,7 @@ private boolean tryCacheHeaders(@NotNull AudioFileFetch fetch) throws IOExceptio
98105 private AudioFileFetch requestHeaders () throws IOException {
99106 AudioFileFetch fetch = new AudioFileFetch (cacheHandler );
100107 if (cacheHandler == null || !tryCacheHeaders (fetch ))
101- requestChunk (file .getFileId (), 0 , fetch );
108+ requestChunk (file .getFileId (), 0 , fetch , false );
102109
103110 fetch .waitChunk ();
104111 return fetch ;
@@ -119,7 +126,7 @@ public void open() throws IOException {
119126 }
120127
121128 private void requestChunk (int index ) {
122- requestChunk (file .getFileId (), index , this );
129+ requestChunk (file .getFileId (), index , this , false );
123130 chunksBuffer .requested [index ] = true ; // Just to be sure
124131 }
125132
@@ -142,8 +149,8 @@ public void writeHeader(byte id, byte[] bytes, boolean cached) {
142149 }
143150
144151 @ Override
145- public void streamError (short code ) {
146- LOGGER .fatal (String .format ("Stream error, code: %d" , code ));
152+ public void streamError (int chunkIndex , short code ) {
153+ LOGGER .fatal (String .format ("Stream error, index: %d, code: %d" , chunkIndex , code )); // TODO: Fatal
147154 }
148155
149156 @ Override
0 commit comments