Always seek to starting position

This commit is contained in:
Roderick van Domburg 2021-12-30 21:52:15 +01:00
parent 05c768f612
commit 286a031d94
No known key found for this signature in database
GPG key ID: A9EF5222A26F0451
2 changed files with 17 additions and 8 deletions

View file

@ -387,6 +387,10 @@ impl AudioFileStreaming {
bytes_per_second: usize, bytes_per_second: usize,
play_from_beginning: bool, play_from_beginning: bool,
) -> Result<AudioFileStreaming, Error> { ) -> Result<AudioFileStreaming, Error> {
// When the audio file is really small, this `download_size` may turn out to be
// larger than the audio file we're going to stream later on. This is OK; requesting
// `Content-Range` > `Content-Length` will return the complete file with status code
// 206 Partial Content.
let download_size = if play_from_beginning { let download_size = if play_from_beginning {
INITIAL_DOWNLOAD_SIZE INITIAL_DOWNLOAD_SIZE
+ max( + max(

View file

@ -867,8 +867,7 @@ impl PlayerTrackLoader {
let mut decrypted_file = AudioDecrypt::new(key, encrypted_file); let mut decrypted_file = AudioDecrypt::new(key, encrypted_file);
// Parsing normalisation data and starting playback from *beyond* the beginning // Parsing normalisation data will trigger a seek() so always start in random access mode.
// will trigger a seek() so always start in random access mode.
stream_loader_controller.set_random_access_mode(); stream_loader_controller.set_random_access_mode();
let normalisation_data = match NormalisationData::parse_from_file(&mut decrypted_file) { let normalisation_data = match NormalisationData::parse_from_file(&mut decrypted_file) {
@ -923,13 +922,19 @@ impl PlayerTrackLoader {
} }
}; };
let mut stream_position_pcm = 0; // Ensure the starting position. Even when we want to play from the beginning,
// the cursor may have been moved by parsing normalisation data. This may not
// matter for playback (but won't hurt either), but may be useful for the
// passthrough decoder.
let position_pcm = PlayerInternal::position_ms_to_pcm(position_ms); let position_pcm = PlayerInternal::position_ms_to_pcm(position_ms);
let stream_position_pcm = match decoder.seek(position_pcm) {
if !play_from_beginning { Ok(_) => position_pcm,
match decoder.seek(position_pcm) { Err(e) => {
Ok(_) => stream_position_pcm = position_pcm, warn!(
Err(e) => error!("PlayerTrackLoader::load_track error seeking: {}", e), "PlayerTrackLoader::load_track error seeking to PCM page {}: {}",
position_pcm, e
);
0
} }
}; };