How to play first n seconds of each file from a playlist
This is straight forward. You have tagged this as VLC, so I'll use that as an example.
First you need a playlist, of course. Here is VLC's wiki to explain how to make a playlist. Make sure you save it to a file.
Then, from commandline, start VLC like this
vlc --playlist-autostart <path/to/playlist.xspf> --run-time=10
This will make vlc immediately play your list, each title for 10 seconds, then stop with VLC left open.
If you start your VLC not from the GUI of the host where the music is played, i.e. via SSH, you need to export the DISPLAY
variable, like this
export DISPLAY=:0; vlc --playlist-autostart <path/to/playlist.xspf> --run-time=10
If you want to VLC immediately close after finished playing, just add vlc://quit
to the end, like this
export DISPLAY=:0; vlc --playlist-autostart <path/to/playlist.xspf> --run-time=10 vlc://quit
I don't know exactly what your use-case is, but If you want this to be completely stealthy, with no VLC shown on the Desktop you could use the commandline frontend. Just substitute vlc with cvlc at the beginning, like this
export DISPLAY=:0; cvlc --playlist-autostart <path/to/playlist.xspf> --run-time=10 vlc://quit
There are of course some more options for playlist behaviour, like -L
for looping or -Z
for shuffle/random, and so on - you best look them up on the official VLC commandline documentation.