You are not logged in.
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
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
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
'mplayer somefile && mplayer -shuffle *'
Offline
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
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
'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).
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.
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
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
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...
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
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
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
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.
Offline
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
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
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.
shopt -s extglob; mplayer %f; mplayer -shuffle !(%f)
Nice.
Mind you, still doesn't satisfy the OP's skipping and quitting requirements.
Last edited by tomk (2012-09-24 14:52:18)
Offline
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
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
shopt -s extglob; IFS=$'\n'; mplayer %f $(\ls !(%f) | shuf)
Last edited by Procyon (2012-09-24 17:10:55)
Offline
One more thing - if you don't like typing, you shouldn't have given the option for a cli-based solution.
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.
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)'
Mind you, still doesn't satisfy the OP's skipping and quitting requirements.
They were more of a wishfully hoped for behavior.
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
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
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
scriptname *partialfilenamesurroundedbywildcards*
I dont see how that would be better than tab completion i.e.
scriptname <partialfilename>Tab
They were more of a wishfully hoped for behavior.
Well, your wish has been granted - by various people, and in various different ways.
Offline
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
Are you using dash as your shell? Procyon's example should work in bash.
~ # echo $SHELL
/bin/bash
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
*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.
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.
Last edited by *nixer (2012-09-25 14:01:56)
Offline
@*nixer: i just checked and it works here...
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline