|  | @@ -31,6 +31,7 @@ void ChunkedByteStream::fetchFileInformation() {
 | 
	
		
			
				|  |  |      endChunk->keepInMemory = true;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      chunks.push_back(endChunk);
 | 
	
		
			
				|  |  | +    requestChunk(0);
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  std::shared_ptr<AudioChunk> ChunkedByteStream::getChunkForPosition(size_t position) {
 | 
	
	
		
			
				|  | @@ -57,11 +58,14 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
 | 
	
		
			
				|  |  |      std::scoped_lock lock(this->readMutex);
 | 
	
		
			
				|  |  |      auto chunk = getChunkForPosition(pos);
 | 
	
		
			
				|  |  |      uint16_t chunkIndex = this->pos / AUDIO_CHUNK_SIZE;
 | 
	
		
			
				|  |  | -    for (auto it = chunks.begin(); it != chunks.end();) {
 | 
	
		
			
				|  |  | -        if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
 | 
	
		
			
				|  |  | -            it = chunks.erase(it);
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            it++;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (loadAheadEnabled) {
 | 
	
		
			
				|  |  | +        for (auto it = chunks.begin(); it != chunks.end();) {
 | 
	
		
			
				|  |  | +            if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
 | 
	
		
			
				|  |  | +                it = chunks.erase(it);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                it++;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -85,7 +89,7 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
 | 
	
		
			
				|  |  |          pos += read;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          auto nextChunkPos = ((chunkIndex + 1) * AUDIO_CHUNK_SIZE) + 1;
 | 
	
		
			
				|  |  | -        if (loadAheadEnabled && nextChunkPos + AUDIO_CHUNK_SIZE < fileSize) {
 | 
	
		
			
				|  |  | +        if (loadAheadEnabled && nextChunkPos  < fileSize) {
 | 
	
		
			
				|  |  |              auto nextChunk = getChunkForPosition(nextChunkPos);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              if (nextChunk == nullptr) {
 | 
	
	
		
			
				|  | @@ -117,7 +121,6 @@ size_t ChunkedByteStream::attemptRead(uint8_t *buffer, size_t bytes, std::shared
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void ChunkedByteStream::seek(size_t nbytes) {
 | 
	
		
			
				|  |  |      std::scoped_lock lock(this->readMutex);
 | 
	
		
			
				|  |  | -    BELL_LOG(info, "cspot", "seeking to %d", nbytes);
 | 
	
		
			
				|  |  |      pos = nbytes;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 |