1

The problem: I've for example 16 tracks in one folder but I only want to play 1 - 7. How do I do this in MPlayer? The following:

mplayer 1.mp3 - 7.mp3

is not the right way. Is it even possible in MPlayer without writing out every filename?

2 Answers 2

0

As far as I am aware this is not possible from within MPlayer itself but a little command line magic can produce some great results.

The following is perhaps a little clumsy but works well enough here with the naming convention that you have specified:

mplayer $(find . -maxdepth 1 -name "[1-7].mp3" | ls -v)

Brief explanation:

  • find . -maxdepth 1: Search in the current directory with no recursion.
  • -name "[1-7].mp3": Find mp3s that have only the numerals 1-7 as their filename. The [1-7] section demonstrates Bash range expression where numbers 1 and 7 are matched as well as all numbers between.
  • ls -v : Sort the search so the playback will be numerically based.

Doubtless there are other ways but this works well enough and if your actual filenames are different it would be simply a matter of changing the regular expression in the find syntax to match...

2
  • Perfect thank you. Never thought about using other linux tools.
    – okabekudo
    Oct 25, 2016 at 15:14
  • @andrew.46, This doesn't work. It plays all of the mp3s in the directory. Can you fix it? It doesn't really make since to pipe the list to ls, does it?
    – RobertL
    Jun 26, 2019 at 7:57
0

In this case, the only other tool you need is your shell command line.

mplayer [1-7].mp3

That example uses shell globbing (aka pathname expansion) to select the files you want to play. However, if you want to play tracks 8 to 11, for example, it should look more like this:

mplayer [89].mp3 1[01].mp3

For more information see 2.13. Pattern Matching Notation in the Posix specification, especially the sub-section 2.13.3 Patterns Used for Filename Expansion.

Also see the Pathname Expansion section of your shell man page ($man sh) and the section following that about Shell Pattern Matching.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .