9 Commits

Author SHA1 Message Date
586c0b88eb Change stop key to 's' for better compatibility
All checks were successful
Build and Release / build-and-release (push) Successful in 59s
- Replace Shift+Space with 's' key for stop functionality
- Update status bar shortcuts to reflect the change
- Bump version to 0.1.5
2025-12-06 16:42:44 +01:00
8e2989731e Add Shift+Space to stop playback
- Shift+Space now stops playback and resets position
- Updated status bar to show stop shortcut
- Shortened status bar text to fit stop command
2025-12-06 16:30:28 +01:00
bda76ba5a0 Bump version to 0.1.4
All checks were successful
Build and Release / build-and-release (push) Successful in 50s
2025-12-06 16:23:16 +01:00
c4adb30d7b Fix NixOS hash update to use local tarball
Use local tarball hash instead of downloading to avoid race condition where download happens before upload completes
2025-12-06 16:22:13 +01:00
3ab70950e0 Bump version to 0.1.3
All checks were successful
Build and Release / build-and-release (push) Successful in 50s
2025-12-06 16:08:45 +01:00
f2f79cc0d2 Add video support and improve mpv process management
- Enable video playback by removing --no-video flag
- Add --profile=fast for better performance
- Add --audio-display=no to prevent cover art windows
- Implement mpv process respawn when closed
- Add process death detection and cleanup
- Show refresh status immediately in title bar
- Fix playlist playback after clearing
2025-12-06 16:07:50 +01:00
4b2757b17f Bump version to 0.1.2
All checks were successful
Build and Release / build-and-release (push) Successful in 57s
2025-12-06 15:57:19 +01:00
bee25505c0 Bump version to 0.1.1
All checks were successful
Build and Release / build-and-release (push) Successful in 50s
2025-12-06 15:24:48 +01:00
b4084b9dcf Fix NixOS config path in release workflow 2025-12-06 15:23:43 +01:00
5 changed files with 108 additions and 22 deletions

View File

@@ -93,27 +93,22 @@ jobs:
run: |
VERSION="${{ steps.version.outputs.VERSION }}"
# Get hash from the local tarball (already built)
NEW_HASH=$(sha256sum release/cm-player-linux-x86_64.tar.gz | cut -d' ' -f1)
NIX_HASH="sha256-$(python3 -c "import base64, binascii; print(base64.b64encode(binascii.unhexlify('$NEW_HASH')).decode())")"
# Clone nixosbox repository
git clone https://$GITEA_TOKEN@gitea.cmtec.se/cm/nixosbox.git nixosbox-update
cd nixosbox-update
# Get hash for the new release tarball
TARBALL_URL="https://gitea.cmtec.se/cm/cm-player/releases/download/$VERSION/cm-player-linux-x86_64.tar.gz"
# Download tarball to get correct hash
curl -L -o cm-player.tar.gz "$TARBALL_URL"
# Convert sha256 hex to base64 for Nix hash format using Python
NEW_HASH=$(sha256sum cm-player.tar.gz | cut -d' ' -f1)
NIX_HASH="sha256-$(python3 -c "import base64, binascii; print(base64.b64encode(binascii.unhexlify('$NEW_HASH')).decode())")"
# Update the NixOS configuration
sed -i "s|version = \"v[^\"]*\"|version = \"$VERSION\"|" hosts/services/cm-player.nix
sed -i "s|sha256 = \"sha256-[^\"]*\"|sha256 = \"$NIX_HASH\"|" hosts/services/cm-player.nix
sed -i "s|version = \"v[^\"]*\"|version = \"$VERSION\"|" hosts/common/cm-player.nix
sed -i "s|sha256 = \"sha256-[^\"]*\"|sha256 = \"$NIX_HASH\"|" hosts/common/cm-player.nix
# Commit and push changes
git config user.name "Gitea Actions"
git config user.email "actions@gitea.cmtec.se"
git add hosts/services/cm-player.nix
git add hosts/common/cm-player.nix
git commit -m "Auto-update cm-player to $VERSION
- Update version to $VERSION with automated release

View File

@@ -1,6 +1,6 @@
[package]
name = "cm-player"
version = "0.1.0"
version = "0.1.5"
edition = "2021"
[dependencies]

View File

@@ -81,6 +81,13 @@ async fn run_app<B: ratatui::backend::Backend>(
player: &mut player::Player,
) -> Result<()> {
loop {
// Check if mpv process died (e.g., user closed video window)
if !player.is_process_alive() && state.player_state != PlayerState::Stopped {
state.player_state = PlayerState::Stopped;
state.current_position = 0.0;
state.current_duration = 0.0;
}
// Update player properties from MPV
player.update_properties();
@@ -105,7 +112,7 @@ async fn run_app<B: ratatui::backend::Backend>(
if event::poll(std::time::Duration::from_millis(100))? {
if let Event::Key(key) = event::read()? {
if key.kind == KeyEventKind::Press {
handle_key_event(state, player, key).await?;
handle_key_event(terminal, state, player, key).await?;
}
}
}
@@ -118,7 +125,7 @@ async fn run_app<B: ratatui::backend::Backend>(
Ok(())
}
async fn handle_key_event(state: &mut AppState, player: &mut player::Player, key: KeyEvent) -> Result<()> {
async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, state: &mut AppState, player: &mut player::Player, key: KeyEvent) -> Result<()> {
// Handle search mode separately
if state.search_mode {
match key.code {
@@ -220,6 +227,13 @@ async fn handle_key_event(state: &mut AppState, player: &mut player::Player, key
tracing::info!("Playing: {:?} (playlist: {} tracks)", path, state.playlist.len());
}
}
(KeyCode::Char('s'), _) => {
// s: Stop playback
state.player_state = PlayerState::Stopped;
state.current_position = 0.0;
state.current_duration = 0.0;
tracing::info!("Stopped");
}
(KeyCode::Char(' '), _) => {
match state.player_state {
PlayerState::Playing => {
@@ -261,6 +275,7 @@ async fn handle_key_event(state: &mut AppState, player: &mut player::Player, key
}
(KeyCode::Char('r'), _) => {
state.is_refreshing = true;
terminal.draw(|f| ui::render(f, state))?; // Show "Refreshing library..." immediately
tracing::info!("Rescanning...");
let cache_dir = cache::get_cache_dir()?;
let new_cache = scanner::scan_paths(&state.config.scan_paths.paths)?;

View File

@@ -27,8 +27,9 @@ impl Player {
// Spawn MPV with IPC server
let process = Command::new("mpv")
.arg("--idle")
.arg("--no-video")
.arg("--no-terminal")
.arg("--profile=fast")
.arg("--audio-display=no") // Don't show cover art for audio files
.arg(format!("--input-ipc-server={}", socket_path.display()))
.stdin(Stdio::null())
.stdout(Stdio::null())
@@ -54,14 +55,60 @@ impl Player {
fn connect(&mut self) -> Result<()> {
if self.socket.is_none() {
let stream = UnixStream::connect(&self.socket_path)
.context("Failed to connect to MPV IPC socket")?;
stream.set_nonblocking(true).ok();
self.socket = Some(stream);
// Try to connect, if it fails, respawn mpv
match UnixStream::connect(&self.socket_path) {
Ok(stream) => {
stream.set_nonblocking(true).ok();
self.socket = Some(stream);
}
Err(_) => {
// MPV probably died, respawn it
self.respawn()?;
let stream = UnixStream::connect(&self.socket_path)
.context("Failed to connect to MPV IPC socket after respawn")?;
stream.set_nonblocking(true).ok();
self.socket = Some(stream);
}
}
}
Ok(())
}
fn respawn(&mut self) -> Result<()> {
// Kill old process if still running
self.process.kill().ok();
self.process.wait().ok();
// Clean up old socket
std::fs::remove_file(&self.socket_path).ok();
// Spawn new MPV process
let process = Command::new("mpv")
.arg("--idle")
.arg("--no-terminal")
.arg("--profile=fast")
.arg("--audio-display=no")
.arg(format!("--input-ipc-server={}", self.socket_path.display()))
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.context("Failed to respawn MPV process")?;
self.process = process;
self.socket = None;
self.is_idle = true;
self.position = 0.0;
self.duration = 0.0;
self.is_paused = false;
// Wait for socket to be created and mpv to be ready
std::thread::sleep(Duration::from_millis(800));
tracing::info!("MPV process respawned");
Ok(())
}
fn send_command(&mut self, command: &str, args: &[Value]) -> Result<()> {
self.connect()?;
@@ -74,7 +121,17 @@ impl Player {
if let Some(ref mut socket) = self.socket {
let msg = format!("{}\n", cmd);
socket.write_all(msg.as_bytes()).context("Failed to write to socket")?;
// Ignore broken pipe errors (mpv closed)
if let Err(e) = socket.write_all(msg.as_bytes()) {
if e.kind() == std::io::ErrorKind::BrokenPipe {
self.socket = None;
self.is_idle = true;
// Clean up dead process
self.process.kill().ok();
return Ok(());
}
return Err(e).context("Failed to write to socket");
}
}
Ok(())
@@ -178,6 +235,25 @@ impl Player {
self.is_idle
}
pub fn is_process_alive(&mut self) -> bool {
// Check if mpv process is still running
match self.process.try_wait() {
Ok(Some(_)) => {
// Process has exited - clean up socket
self.socket = None;
self.is_idle = true;
false
}
Ok(None) => true, // Process is still running
Err(_) => {
// Error checking, assume dead and clean up
self.socket = None;
self.is_idle = true;
false
}
}
}
pub fn seek(&mut self, seconds: f64) -> Result<()> {
self.send_command("seek", &[json!(seconds), json!("relative")])?;
Ok(())

View File

@@ -251,7 +251,7 @@ fn render_status_bar(frame: &mut Frame, state: &AppState, area: Rect) {
frame.render_widget(status_bar, area);
} else {
// Normal mode shortcuts (always shown when not in search mode)
let shortcuts = "/: Search • v: Mark • a: Add to Playlist • c: Clear Playlist • Enter: Play • Space: Pause • ←→: Seek • +/-: Volume • n/p: Next/Prev • r: Rescan • q: Quit";
let shortcuts = "/: Search • v: Mark • a: Add • c: Clear • Enter: Play • Space: Pause • s: Stop • ←→: Seek • +/-: Vol • n/p: Next/Prev • r: Rescan • q: Quit";
let status_bar = Paragraph::new(shortcuts)
.style(Style::default().fg(Theme::muted_text()).bg(Theme::background()))
.alignment(Alignment::Center);