You are not logged in.

#1 2012-09-23 21:04:19

*nixer
Member
Registered: 2011-11-11
Posts: 56

[Solved] Mplayer - Is this possible without a GUI?

Hello.

I'm sorry for pretty much just making a request, but I have no clue where to even begin. My question is the following.

Is it possible to create a script to allow Mplayer to launch a specific file (ie - double-clicking, or cli) in a directory, and then have it randomly (shuffle) play the other files in the directory after the initial track/video has completed?

I could simple call the shuffle, repeat, etc. parameters, but I need it to start on the media file I'm initially launching the script with. Again apologies, but I've never attempted to do something like this before...

Last edited by *nixer (2012-09-25 14:00:36)

Offline

#2 2012-09-23 21:07:11

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Mplayer - Is this possible without a GUI?

I am fairly certain that you can glob when you call mplayer.

$ mplayer ./* -shuffle 

I wouldn't call that a script, but I think that is what you are looking for.

Offline

#3 2012-09-23 21:21:20

*nixer
Member
Registered: 2011-11-11
Posts: 56

Re: [Solved] Mplayer - Is this possible without a GUI?

Yeah. that's what I could have called from the cli, but it just randomly starts on any file in the directory. If I had added that to a bash file, made it the default open with command, and double-clicked a specific file...

#! /bin/bash
mplayer ./* -shuffle -fs

It would just randomly pick any one of the tracks/videos in the directory, and not the one I double-clicked on. I need it to play the initial media file used to launch the script first.

[edit]
It also doesn't seem to allow skipping of tracks <>, and it just shutdown mplayer after finishing the first file played
[/edit]

Last edited by *nixer (2012-09-23 21:25:26)

Offline

#4 2012-09-23 21:25:59

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] Mplayer - Is this possible without a GUI?

'mplayer somefile && mplayer -shuffle *'

Offline

#5 2012-09-23 21:27:42

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Mplayer - Is this possible without a GUI?

mplayer $1 ./* -shuffle -fs 

So that it calls the selected file as the first argument... I don't really use a file manager, so I am not sure if the file will be passed as an argument in the normal way.  I assume it would.

Offline

#6 2012-09-23 21:35:48

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [Solved] Mplayer - Is this possible without a GUI?

Try this in your script:
given the starting filename as an argument, create a temporary playlist of all files except the starting file, call mplayer to play the starting file, and finally call mplayer to play the playlist with -shuffle.

Offline

#7 2012-09-23 22:34:05

*nixer
Member
Registered: 2011-11-11
Posts: 56

Re: [Solved] Mplayer - Is this possible without a GUI?

karol wrote:

'mplayer somefile && mplayer -shuffle *'

Because the 'somefile' variable needs to be typed out, it works in command line, but not as a script in the file manager. I've tried  a few variations at something I vaguely remembered being done in a bash file before to launch a specific file, but they didn't work.

mplayer @f && mplayer -shuffle *.*
mplayer $f && mplayer -shuffle *.*
mplayer %f && mplayer -shuffle *.*

There doesn't seem to be a console variable for a file called by the file manager (Thunar).


WonderWoofy wrote:
mplayer $1 ./* -shuffle -fs 

So that it calls the selected file as the first argument... I don't really use a file manager, so I am not sure if the file will be passed as an argument in the normal way.  I assume it would.

This behaves just like the "mplayer -shuffle ./*" command. The first play file is still random.

tomk wrote:

Try this in your script:
given the starting filename as an argument, create a temporary playlist of all files except the starting file, call mplayer to play the starting file, and finally call mplayer to play the playlist with -shuffle.

This behaves just like Karol's suggestion, and the first file needs to be typed out.

Besides the initial video not being skip ready with the > key (I used Page Up to go to the end), there was the very minor issue of mplayer visibly quitting, and then relaunching. I suppose this would be good enough if I could get it to work when launching from a file manager, for at least videos anyways. Any other ideas?

Last edited by *nixer (2012-09-23 22:36:37)

Offline

#8 2012-09-23 22:40:13

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] Mplayer - Is this possible without a GUI?

*nixer wrote:
karol wrote:

'mplayer somefile && mplayer -shuffle *'

Because the 'somefile' variable needs to be typed out, it works in command line, but not as a script in the file manager.

[karol@black ~]$ type foo
foo is a function
foo () 
{ 
    mplayer $1 && mplayer -shuffle *
}
[karol@black ~]$ foo somefile
MPlayer2 UNKNOWN (C) 2000-2012 MPlayer Team
<blah blah blah>
Playing somefile.
Detected file format: MPEG audio layer 2/3 (libavformat)
<blah blah blah>

You want to "launch a specific file (ie - double-clicking, or cli) in a directory". What is so bad about tab-completion for filenames?


Edit: Maybe you'd be happier with a dedicated app, like cmus. You can pick a file to play using the ncurses interface and set the app to play shuffled files from that directory or your playlist.

Last edited by karol (2012-09-23 22:44:58)

Offline

#9 2012-09-24 01:41:51

*nixer
Member
Registered: 2011-11-11
Posts: 56

Re: [Solved] Mplayer - Is this possible without a GUI?

karol wrote:

You want to "launch a specific file (ie - double-clicking, or cli) in a directory". What is so bad about tab-completion for filenames?

Because I'm horrible at typing a lot. Fast chicken peck at it's best...

karol wrote:

Edit: Maybe you'd be happier with a dedicated app, like cmus. You can pick a file to play using the ncurses interface and set the app to play shuffled files from that directory or your playlist.

Thanks for the suggestion, and I'll look into it for audio files. I guess what I was hoping for was more along the lines of "script_name video_file.mp4" from the cli, or a double-click to launch the same script from the file-manager solution. I did end up getting your above method to work by adding this to Thunar's "Configure custom actions" menu option. It doesn't work as a standalone bash script though.

mplayer %f && mplayer -shuffle *

After that, all I had to do was click on the "Appearance Conditions" tab and check audio, video, and other as options. For some reason, the only video type associated with video were the flv files, and not mp4, m4v, webm, etc.

It's a bit dirty because you can't... playlist skip from first video, hit ESC while first video is playing to completely close mplayer, open the second command in the same mplayer instance (player flashes off then on).

Thanks to everyone who took the time to respond, and have a good night (that is if you're located in the eastern us).

Offline

#10 2012-09-24 09:10:17

PReP
Member
From: Sweden
Registered: 2010-06-13
Posts: 359
Website

Re: [Solved] Mplayer - Is this possible without a GUI?

I made myself a random play-script fpr mplayer like this in the past: https://aur.archlinux.org/packages.php?ID=41543
It has random pitch aswell though (for music), but that can be disabled in the scripts mplayer invocation-lines.

Though i have updated it a bit locally, might need to update the aur-package sometime.


. Main: Intel Core i5 6600k @ 4.4 Ghz, 16 GB DDR4 XMP, Gefore GTX 970 (Gainward Phantom) - Arch Linux 64-Bit
. Server: Intel Core i5 2500k @ 3.9 Ghz, 8 GB DDR2-XMP RAM @ 1600 Mhz, Geforce GTX 570 (Gainward Phantom) - Arch Linux 64-Bit
. Body: Estrogen @ 90%, Testestorone @ 10% (Not scientific just out-of-my-guesstimate-brain)

Offline

#11 2012-09-24 09:57:39

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,033

Re: [Solved] Mplayer - Is this possible without a GUI?

A .desktop file should do what's wanted. With something similar to 'mplayer %f && mplayer -shuffle *' to play the clicked on file and press enter not q to skip files.


You're just jealous because the voices only talk to me.

Offline

#12 2012-09-24 13:05:46

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [Solved] Mplayer - Is this possible without a GUI?

Is it possible I'm the only person who noticed that 'mplayer %f && mplayer -shuffle *' plays the file given as the argument twice - once explicitly, and a second time as part of the shuffle? Of course, the OP maybe OK with that, but it wasn't the requirement.

Anyway, that's why I was using a playlist. The following works with both thunar and spacefm, you can skip and quit during the first (or any) video, it's one mplayer command, but the window closes and reopens between videos.

#!/bin/bash

echo "$1" > /tmp/playlist
ls $(pwd)/* | grep -v "$1" | shuf >> /tmp/playlist
mplayer -playlist /tmp/playlist
rm /tmp/playlist

One more thing - if you don't like typing, you shouldn't have given the option for a cli-based solution. smile

Offline

#13 2012-09-24 13:52:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] Mplayer - Is this possible without a GUI?

tomk wrote:

Is it possible I'm the only person who noticed that 'mplayer %f && mplayer -shuffle *' plays the file given as the argument twice - once explicitly, and a second time as part of the shuffle?)

I'm not using any file manager, but 'mplayer foo && mplayer -shuffle *' will play the foo and than switch to another, randomly picked file. It may be e.g. the next one, but it's random. Do you mean it plays foo, foo again and than bar every time or that foo will be played as one of the files in the shuffle?

Offline

#14 2012-09-24 14:07:34

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Mplayer - Is this possible without a GUI?

tomk wrote:

Is it possible I'm the only person who noticed that 'mplayer %f && mplayer -shuffle *' plays the file given as the argument twice - once explicitly, and a second time as part of the shuffle?

shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)

Offline

#15 2012-09-24 14:49:27

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [Solved] Mplayer - Is this possible without a GUI?

karol wrote:

Do you mean it plays foo, foo again and than bar every time or that foo will be played as one of the files in the shuffle?

The latter.

Procyon wrote:

shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)

Nice. smile
Mind you, still doesn't satisfy the OP's skipping and quitting requirements.

Last edited by tomk (2012-09-24 14:52:18)

Offline

#16 2012-09-24 16:19:54

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: [Solved] Mplayer - Is this possible without a GUI?

Maybe you can put all of the items into a playlist via find and play that playlist via "mplayer -playlist file.m3u" ?
something like:

pls=$RANDOM.pls && find /full/path/to/multimedia/files/ -maxdepth 1 >$pls && mplayer -playlist $pls -shuffle ; rm $pls

Last edited by kokoko3k (2012-09-24 16:21:39)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#17 2012-09-24 16:23:17

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] Mplayer - Is this possible without a GUI?

kokoko3k wrote:

Maybe you can put all of the items into a playlist via find and play that playlist via "mplayer -playlist file.m3u" ?
something like:

pls=$RANDOM.pls && find /full/path/to/multimedia/files/ -maxdepth 1 >$pls && mplayer -playlist $pls -shuffle ; rm $pls

How do you select the file you want to play first?

Offline

#18 2012-09-24 17:10:04

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Mplayer - Is this possible without a GUI?

shopt -s extglob; IFS=$'\n'; mplayer %f $(\ls !(%f) | shuf)

Last edited by Procyon (2012-09-24 17:10:55)

Offline

#19 2012-09-25 00:44:07

*nixer
Member
Registered: 2011-11-11
Posts: 56

Re: [Solved] Mplayer - Is this possible without a GUI?

tomk wrote:

One more thing - if you don't like typing, you shouldn't have given the option for a cli-based solution. smile

Well something like the following would have been simple enough for launching at least audio from a console. The above method for Thunar didn't function from the command line (%f was ignored in a bash script?).

scriptname *partialfilenamesurroundedbywildcards*

I guess I was hoping for a single solution script for a console, or a file manager.


Procyon wrote:

shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)

# mps *emon*
/usr/local/bin/mps: line 2: syntax error near unexpected token `('
/usr/local/bin/mps: line 2: `shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)'
tomk wrote:

Mind you, still doesn't satisfy the OP's skipping and quitting requirements.

They were more of a wishfully hoped for behavior.


Procyon wrote:

shopt -s extglob; IFS=$'\n'; mplayer %f $(\ls !(%f) | shuf)

This just randomly plays the files in the directory, and doesn't play the initial file the script was launched from.

Last edited by *nixer (2012-09-25 00:45:34)

Offline

#20 2012-09-25 01:20:07

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] Mplayer - Is this possible without a GUI?

*nixer wrote:
Procyon wrote:

shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)

# mps *emon*
/usr/local/bin/mps: line 2: syntax error near unexpected token `('
/usr/local/bin/mps: line 2: `shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)'

Are you using dash as your shell? Procyon's example should work in bash.

Offline

#21 2012-09-25 06:34:48

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: [Solved] Mplayer - Is this possible without a GUI?

karol wrote:

How do you select the file you want to play first?

You're right, here is another:

#Said $1 the full path to the file to play:

#!/bin/bash

pls=/tmp/$RANDOM.pls

echo "$1" >$pls && find $(dirname "$1") -maxdepth 1 |grep -v "$1" |shuf >>$pls

mplayer -playlist $pls

rm $pls

Last edited by kokoko3k (2012-09-25 06:36:50)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#22 2012-09-25 08:38:06

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [Solved] Mplayer - Is this possible without a GUI?

*nixer wrote:
scriptname *partialfilenamesurroundedbywildcards*

I dont see how that would be better than tab completion i.e.

scriptname <partialfilename>Tab
*nixer wrote:

They were more of a wishfully hoped for behavior.

Well, your wish has been granted - by various people, and in various different ways. smile

Offline

#23 2012-09-25 10:28:22

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Mplayer - Is this possible without a GUI?

*nixer wrote:
Procyon wrote:

shopt -s extglob; IFS=$'\n'; mplayer %f $(\ls !(%f) | shuf)

This just randomly plays the files in the directory, and doesn't play the initial file the script was launched from.

Note the command is mplayer %f $(\ls !(%f)|shuf)

$ touch $(seq 10)
$ file=4
$ shopt -s extglob
$ IFS=$'\n'
$ echo $file $(ls !($file) | shuf)
4 9 8 6 2 5 3 1 10 7

Offline

#24 2012-09-25 11:57:45

*nixer
Member
Registered: 2011-11-11
Posts: 56

Re: [Solved] Mplayer - Is this possible without a GUI?

karol wrote:

Are you using dash as your shell? Procyon's example should work in bash.

~ # echo $SHELL
/bin/bash
kokoko3k wrote:

You're right, here is another:

#Said $1 the full path to the file to play:

#!/bin/bash

pls=/tmp/$RANDOM.pls

echo "$1" >$pls && find $(dirname "$1") -maxdepth 1 |grep -v "$1" |shuf >>$pls

mplayer -playlist $pls

rm $pls

This quits playback as soon as the initial video completes, or is attempted to be skipped with Page Up

tomk wrote:
*nixer wrote:
scriptname *partialfilenamesurroundedbywildcards*

I dont see how that would be better than tab completion i.e.

Oops... Pressing TAB only displayed the possible file names with no way for myself to select them. I didn't realize that something needed configuring, ie - https://wiki.archlinux.org/index.php/Ba … completion. Although, I find that it does still require more key presses to accomplish the same goal than with using wildcards.

Procyon wrote:

Note the command is mplayer %f $(\ls !(%f)|shuf)

$ touch $(seq 10)
$ file=4
$ shopt -s extglob
$ IFS=$'\n'
$ echo $file $(ls !($file) | shuf)
4 9 8 6 2 5 3 1 10 7

I'm not quite sure what you mean. Just add the "mplayer %f $(\ls !(%f)|shuf)" to the bash script? Or does it have something to do with this segment I found on the Bash wiki page?

Note: Bash users should make sure extglob is enabled: shopt -s extglob, for example by adding it to the .bashrc. It is enabled by default if using Bash completion. Zsh users should do: setopt kshglob instead.

I've only ever used the default .bashrc with the addition of a colored prompt.

EDIT;

Well, I've added mplayer to the .bashrc for tab auto-completion, and the above scripts still don't work. I guess the Thunar method will be sufficient enough, and I'll just forget about console for now. Thanks to everyone who took the time to respond to my queries. wink

Last edited by *nixer (2012-09-25 14:01:56)

Offline

#25 2012-09-25 14:08:01

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: [Solved] Mplayer - Is this possible without a GUI?

@*nixer: i just checked and it works here...


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

Board footer

Powered by FluxBB