LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2007, 10:58 AM   #1
Nonc
Member
 
Registered: Mar 2006
Location: Nottingham, England
Distribution: Ubuntu
Posts: 59

Rep: Reputation: 15
Script to play random movie file


hi,

i would like to write/have a script that i can run that randomly picks a file and plays it. Im not bothered what language it uses.

id like to be able to have a list where i put in the names and respective players of the file and then it randomly chooses one and starts to play it. it could even just randomly choose a command, where the command is to start the file.

can someone point me to a tut that will have the stuff on how to do it, or if you want you can write it, i imagine its not too difficult.

cheers
nonc
 
Old 11-26-2007, 03:58 AM   #2
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
I wrote a silly shell script once that does something similar: pick a random picture from a folder and set it as the wallpaper.
If you just replace picture with movie, and run mplayer instead of bsetbg or whatever, you could pretty much do the same for your need.
This is the script that I wrote:
Code:
    #!/usr/bin/bash
    #randwall.sh: Randomly sets wallpaper each time it’s run

    #Count how many images are there in my folder..
    WCOUNT=`ls -1 ~/pictures/recent/* | wc -l`;

    #Generate a random number within that range..
    num=$[ ( $RANDOM % $WCOUNT ) + 1 ];

    #Pick up that particular image..
    MYPIC=`ls ~/pictures/recent/* |sed -n ‘ ‘$num’p ‘`;

    #and set it as the wallpaper!
    bsetbg $MYPIC;
So fiddle around with it until it does what you need. e.g you can run it inside a while [ 1 ] loop so that it picks the next random movie once the first one is done, etc. Check out tldp's bash guides for more tips. http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
 
Old 11-26-2007, 10:22 AM   #3
cetialphav
Member
 
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88

Rep: Reputation: 16
A Tcl version

Here is a Tcl script that I use to do something similar. It grabs a random file out of the current directory and plays it with mplayer.

Code:
#!/usr/bin/tclsh

proc lrandom L {lindex $L [expr {int(rand()*[llength $L])}]}

set fileList [glob *]
set f [lrandom $fileList]
puts "Playing $f"
exec gmplayer $f &
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to play movie mirlipi Red Hat 1 08-03-2007 06:13 AM
using /dev/random to output random numbers on a text file guguma Programming 4 04-02-2007 01:42 PM
KDE Random wallpaper or script to create symbolic links to random files cvelasquez Linux - Software 2 02-26-2007 06:48 PM
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 07:16 AM
Play movie chinaundead Mandriva 6 02-28-2004 06:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration