Skip to content

Commit 412c969

Browse files
committed
Auto-restart network streams when pressing Play after disconnect
1 parent 7b40df3 commit 412c969

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

src/main.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,14 @@ async fn run_gui(app_state: Arc<Mutex<AppState>>, mut active_stream: Option<audi
409409
state.spectrum_history.clear();
410410
for _ in 0..120 { state.spectrum_history.push_back(vec![0.0; 1024]); }
411411
state.is_paused = false;
412+
} else if state.playlist_index >= state.playlist.len() && !state.playlist.is_empty() {
413+
if state.duration_seconds == 0.0 {
414+
state.playlist_index = state.playlist.len() - 1;
415+
} else {
416+
state.playlist_index = 0;
417+
}
418+
state.load_request = Some(state.playlist[state.playlist_index].clone());
419+
state.is_paused = false;
412420
} else {
413421
state.is_paused = !state.is_paused;
414422
}
@@ -1194,6 +1202,14 @@ async fn run_gui(app_state: Arc<Mutex<AppState>>, mut active_stream: Option<audi
11941202
state.spectrum_history.clear();
11951203
for _ in 0..120 { state.spectrum_history.push_back(vec![0.0; 1024]); }
11961204
state.is_paused = false;
1205+
} else if state.playlist_index >= state.playlist.len() && !state.playlist.is_empty() {
1206+
if state.duration_seconds == 0.0 {
1207+
state.playlist_index = state.playlist.len() - 1;
1208+
} else {
1209+
state.playlist_index = 0;
1210+
}
1211+
state.load_request = Some(state.playlist[state.playlist_index].clone());
1212+
state.is_paused = false;
11971213
} else {
11981214
state.is_paused = !state.is_paused;
11991215
}
@@ -1301,7 +1317,22 @@ where std::io::Error: From<<B as Backend>::Error>
13011317
}
13021318
KeyCode::Char(' ') => {
13031319
let mut state = app_state.lock().unwrap();
1304-
state.is_paused = !state.is_paused;
1320+
if state.current_seconds >= state.duration_seconds - 0.1 && state.duration_seconds > 0.0 {
1321+
state.seek_request = Some(0.0);
1322+
state.spectrum_history.clear();
1323+
for _ in 0..120 { state.spectrum_history.push_back(vec![0.0; 1024]); }
1324+
state.is_paused = false;
1325+
} else if state.playlist_index >= state.playlist.len() && !state.playlist.is_empty() {
1326+
if state.duration_seconds == 0.0 {
1327+
state.playlist_index = state.playlist.len() - 1;
1328+
} else {
1329+
state.playlist_index = 0;
1330+
}
1331+
state.load_request = Some(state.playlist[state.playlist_index].clone());
1332+
state.is_paused = false;
1333+
} else {
1334+
state.is_paused = !state.is_paused;
1335+
}
13051336
}
13061337
KeyCode::Right => {
13071338
let mut state = app_state.lock().unwrap();

0 commit comments

Comments
 (0)