Moode Forum
/var/local/www/currentsong.txt is empty sometimes - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Feature requests (https://moodeaudio.org/forum/forumdisplay.php?fid=8)
+--- Thread: /var/local/www/currentsong.txt is empty sometimes (/showthread.php?tid=3797)



/var/local/www/currentsong.txt is empty sometimes - adrii - 05-11-2021

When a song file is paused the currentsong.txt file may be empty while the state is being changed. Here is an example of printing it repeatedly while pausing the stereo test track



Code:
pi@moode:~ $ cat /var/local/www/currentsong.txt 
file=SDCARD/Stereo Test/LRMonoPhase4.flac
artist=Koz
album=Stereo Test
title=LR Channel And Phase
coverurl=/coverart.php/SDCARD%2FStereo%20Test%2FLRMonoPhase4.flac
track=1
date=1997
composer=
encoded=16/48 FLAC
bitrate=435 kbps
outrate=16 bit, 44.1 kHz, Stereo, 1.411 Mbps
volume=13
mute=0
state=play
pi@moode:~ $ cat /var/local/www/currentsong.txt 
pi@moode:~ $ cat /var/local/www/currentsong.txt 
pi@moode:~ $ cat /var/local/www/currentsong.txt 
file=SDCARD/Stereo Test/LRMonoPhase4.flac
artist=Koz
album=Stereo Test
title=LR Channel And Phase
coverurl=/coverart.php/SDCARD%2FStereo%20Test%2FLRMonoPhase4.flac
track=1
date=1997
composer=
encoded=16/48 FLAC
bitrate=131 kbps
outrate=0 bps
volume=13
mute=0
state=pause

The file is also sometimes empty for a short while after Moode startup is complete, but before anything is played, so it is difficult to interpret what an empy file means.

Adrian


RE: /var/local/www/currentsong.txt is empty sometimes - Tim Curtis - 05-11-2021

A program thats checking the file could see it as empty if it reads it between the time its opened/truncated and then written/closed. This time interval would be really short though, in the sub milliseconds range because there are just a few lines of code doing the file open/write/close. Have a look at function updExtMetaFile() in worker.php. Just assume its last state if you see it as empty.

The file being empty at startup is a bug. It's being created afresh without first checking to see if it already exists. I've added to the TODO list to fix for upcoming 7.3.0 release.


RE: /var/local/www/currentsong.txt is empty sometimes - adrii - 05-11-2021

Hi Tim

I was using up arrow to repeat the command, and the file was empty three times, so it was probably empty for around a second. Because the file is opened for writing before the data is collected, maybe some of the data collection/processing is taking longer than expected (maybe interupted by another process) and the file then has zero length for longer than expected (I am on a Pi Zero with not much CPU headroom).

Regarding the implementation, it might avoid access issues if the file was written to another name and then renamed to currentsong.txt afterwards. (The zero-length window could be reduced by opening the file for writing after the data is collected, but the rename should avoid the empty file altogether.)

Adrian.


RE: /var/local/www/currentsong.txt is empty sometimes - Tim Curtis - 05-11-2021

Good ideas. I'll run some tests.