RSS Feed

Raspberry Pi as a Multimedia Player

Posted on

So, I ended this weekend by playing with my stranded Raspberry Pi.

As of today, I have three computers with three different operating systems. Raspberry Pi uses Linux based on Debian distro. Actually, I’d like to use a kind of multimedia OS. However I have to download the OS of more than one Gig size in the office😛. My second computer is Mangbook. Ya you know it, it uses OSX as an operating system. And, the last computer is the brand new i5 desktop computer uses Windows OS, of course, it’s for my lil’ brother to finish his thesis.

What have I done to my Raspberry Pi?

My objection is very simple. It is to play the full HD video clips and movies using the tiniest computer in the world, the Raspberry Pi.  I want to play movies or video clips in my full HD TV that has no feature of plug and play the video files via its USB port.  I forgot what the OS my Raspberry Pi uses. In this OS, there is a video player but it should be called in the Terminal. I can not simply click the movie file in the File Manager (it’s like Windows Explorer in Windows OS) and play it. It has no GUI yet. The video player is omxplayer. To play the video file, I have to type this line in the Terminal:

omxplayer -o hdmi thefile

It’s good for me to watch only one movie video. Nevertheless, if I want to watch the TV serials or playing all video clips in the folder, I am disturbed. So, I write this bash script to tackle the problem.

Playing all files in a folder

Save this script in /usr/bin/omxplayerall

#!/bin/bash
for thefile in $2/*
do
  echo "Playing file $thefile..."
  omxplayer -o $1 "$thefile"
done

Add +x in chmod by typing this line in the Terminal, so the command can be used by ordinary users.

chmod +x /usr/bin/omxplayerall

To play all files in a folder, type this line in the Terminal

omxplayerall hdmi path/to/videoclips/file

But… if the directory name has white spaces then you have to type this command in the desired video clips folder

omxplayerall hdmi .

To stop the current played file and playing the next file, press Ctrl+C once.
To stop the playing all files in a folder command, press Ctrl+C repeatedly.

This is better… particularly for watching TV serials. But em, it is not perfect when I want to watch the video clips with shuffle mode.

Playing all files in a folder shuffled

Save this script in /usr/bin/omxplayershuffle

#!/bin/bash
files=($2/*)
limit=${#files[@]}
counter=1
echo "PLAYING $limit FILES..."
file_played[1]=""

while [ "$counter" -le "$limit" ]
do
  file_ran="${files[RANDOM % ${#files[@]}]}"

  #skip the played file
  for filex in "${file_played[@]}"
  do
    play="TRUE"
    if [ "$file_ran" == "$filex" ]; then
      play="FALSE"
      break
    fi
  done

  if [ "$play" == "TRUE" ]; then
    echo "Playing file #$counter: $file_ran"
    omxplayer -o $1 "$file_ran"
    file_played[$counter]="$file_ran"
    let counter=$counter+1
  fi
done

echo "THANK YOU FOR WATCHING...!"

Add +x in chmod by typing this line in the Terminal, so the command can be used by ordinary users.

chmod +x /usr/bin/omxplayershuffle

To play all files in a folder, type this line in the Terminal

omxplayershuffle hdmi path/to/videoclips/file

But… if the directory name has white spaces then you have to type this command in the desired video clips folder

omxplayershuffle hdmi .

To stop the current played file and playing the next file, press Ctrl+C once.
To stop the playing all files in a folder command, press Ctrl+C repeatedly.

Click the file to play

This is the final section. You can play the file by right clicking the file in the explorer or File Manager. And then select Open With then select Custom Command Line tab. In the Command line to execute: box, fill this line:

omxplayer -o hdmi %f

The disadvantage of this way is you can not stop the video until it finished playing the file. Haha…

I hope this sharing would be useful for you. Thanks for reading!

About mangkum

Models maker and fans: building view-controller-models, financial models, statistical models and a fan of super models.

2 responses »

  1. what would be really good would be an infinite shuffle. So at the moment the script shuffles the folder and stops. How about it just loops back to another shuffle?

    Reply
  2. Very nice article🙂 I was able to get omxplayerall to work very easy🙂 What can I do for omxplayerall to start over? To start from beginning after all MP3 are played? Thanks.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: