Here’s a quick tip for today.
If you’ve got a few spares Raspberry Pis lying around (like I do) then sometimes they can come in handy as a portable media player. However, given that I don’t know the capabilities of the television with which the Pi will be used (at the bare minimum it has HDMI) then I am left guessing whether or not things like using the remote control will work.
To save messing around, I decided to configure OSMC on the Pi to autoplay a single video located on a USB stick. This is how you do it:
- Locate or create /home/osmc/.kodi/userdata/autoexec.py
- Add the following lines to the file:
import xbmc
xbmc.executebuiltin( “PlayMedia(/media/[labelofusbstick]/[path]/[videofilename])” )
You’ll need to replace [labelofusbstick] with the volume label of the USB stick, [path] with the folder structure where the video is located, and [videofilename] with the filename of the video.
After you save the file, reboot your Raspberry Pi and when it boots up again it should launch straight into the video!
16 comments
Skip to comment form
Ok I could google this…. But…. Can you get it to play a folder on boot and shuffle the contents? Think jukebox style.
Yeah, you could do something like the last post @ http://forum.kodi.tv/showthread.php?tid=69797
# Autoplay videodirectory
import os, xbmc
# set path to dir you want to play
path=”/media/pathtovideodir”
dirList=os.listdir(path)
dirList.sort()
videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
videoList.clear()
for fname in dirList:
videoList.add(path + “\” + fname)
# shuffle playlist
#videoList.unshuffle()
# put playlist on repeat
xbmc.executebuiltin(“xbmc.playercontrol(RepeatAll)”)
# play playlist
xbmc.Player().play(videoList)
Google is so over rated 🙂
Hi Boyd.
Total noob here..
Some questions for you.
Are you running OSMC alone, not on Ubuntu or other desktops?
How, where, and with what do you write Linux commands to OSMC?
Taking the SD Card out og my Pi2, and putting it in my Win pc, i cant find the files that you write about.
Regards from noob.
Author
Ah, fair question 🙂
My Pi2 is running OSMC by itself.
To update the file, I connected to the Pi2 using SSH using Putty which will give you the remote text mode interface to the unit. You’ll need the IP address or hostname of the Pi2 to connect as well as the username and passsword (by default these should be “osmc” without quotation marks).
Once you are connected, type the following:
nano /home/osmc/.kodi/userdata/autoexec.py
This will open a text editor where you can make the required updates. Once completed, press Ctrl+S to save and then Ctrl+X to exit.
Reboot the Pi2 and you should be off and running 🙂
Thx for the quick reply.
I need it to boot up and start playing videos from a folder.
For a clothing store.
Last question (mayby).
How do i locate my usb drive path?
Hi Again..
Found the Linux command line df.
But i get a error from autoexec.py when OSMC starts.
Read log file for error
Is it because its called KODI now, and not XBMC?
So the lines in your link may have changed.
Can you help.
Thanks in advance.
Author
No, particularly given that the path where the file lives already has “kodi” included as the folder name.
The fact that you are getting an error though means that the file is probably being read.
What text did you insert into autoexec.py? Maybe there is a minor error causing it to throw the error.
Its most likely somthing i havent done correctly.
I copied the text from your post, and changed path of video dir to TOSHIBA. (name of my usb stick)
By the way, how do i find the autoexec.py log file?
# Autoplay videodirectory
import os, xbmc
# set path to dir you want to play
path=”/media/TOSHIBA”
dirList=os.listdir(path)
dirList.sort()
videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
videoList.clear()
for fname in dirList:
videoList.add(path + “\” + fname)
# shuffle playlist
#videoList.unshuffle()
# put playlist on repeat
xbmc.executebuiltin(“xbmc.playercontrol(RepeatAll)”)
# play playlist
xbmc.Player().play(videoList)
Author
There should be a general log file for Kodi at /home/.kodi/temp/kodi.log – depending on the level of logging enabled you may see a varying amount of information in there.
Have you tried manually browser to /media/TOSHIBA via Putty to see if it is a valid folder?
cd /media/TOSHIBA and the dir, lists all of my videos.
Heres my df.
osmc@osmc:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 30299164 564872 28172132 2% /
devtmpfs 371332 0 371332 0% /dev
tmpfs 375636 0 375636 0% /dev/shm
tmpfs 375636 5104 370532 2% /run
tmpfs 5120 0 5120 0% /run/lock
tmpfs 375636 0 375636 0% /sys/fs/cgroup
/dev/mmcblk0p1 244988 17311 227677 8% /boot
/dev/sda1 15220160 6762944 8457216 45% /media/TOSHIBA
tmpfs 75128 0 75128 0% /run/user/1000
osmc@osmc:~$
Trying to find the elusive log file is beeing a problem.
osmc@osmc:~$ cd /home/.kodi/temp/kodi.log
-bash: cd: /home/.kodi/temp/kodi.log: No such file or directory
osmc@osmc:~$
osmc@osmc:~$ cd /home
osmc@osmc:/home$ cd /.kodi
-bash: cd: /.kodi: No such file or directory
osmc@osmc:/home$
osmc@osmc:/home$ dir
osmc
osmc@osmc:/home$
am i even logged in correctly?
login as: osmc
OSMC: Open Source Media Center
osmc@192.168.1.61‘s password:osmc
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Oct 4 13:11:54 2015 from 192.168.1.32
osmc@osmc:~$
Author
Ah, okay. My bad.
Try /home/osmc/.kodi/temp/kodi.log
hey
i am having exactly the same problem as Nicolai Hansen.
osmc@osmc:~$ cd /home/osmc/.kodi/temp/kodi.log
-bash: cd: /home/osmc/.kodi/temp/kodi.log: Not a directory
I was wondering if there was ever a solution found for this?
I used:
import xbmc
xbmc.executebuiltin( “PlayMedia(/media/Lexar/A.mp4)” )
to reach a file on my Lexar usb stick which is called A.mp4 – perhaps there is a problem with the path i have written?
Any help much appreciated!
Thank you!
Hey
I am getting exactly the same issue as Nicolai Hansen. When i tried /home/osmc/.kodi/temp/kodi.log
i recieved this:
osmc@osmc:~$ cd /home/osmc/.kodi/temp/kodi.log
-bash: cd: /home/osmc/.kodi/temp/kodi.log: Not a directory
Here is what i typed into autoexec.py
import xbmc
xbmc.executebuiltin( “PlayMedia(/media/Lexar/A.mp4)” )
I am wondering whether the file path is definitely /media/Lexar/A.mp4 ???
Author
Not sure if the path has been changed in subsequent builds used for fresh installation but this solution still works for me.
Are you certain that Lexar is the label assigned to the SD card? Can you browse to that location from the command line?
I know this is an old thread but since it is one of the more common results when googling an auto playing and repeating playlist on boot for Kodi I figured I would chime in on the fixes that were needed.
The first is just simply verifying that you have the path set correctly for your project. I have done a number of projects for customer showrooms and have found, if the files are not too large, simply using a 32 or 64gb sd card and then mapping the /Movies directory through FTP on the clients computer allows them to add and change files at their leisure without even needing to access the Pi which may be stuck to back of the television high on a wall.
The second most common problem is the lost syntax when people copy and paste the code for the autoexec.py script. The portion of code that adds the files from the folder to the playlist must be indented and contain a “/” rather than “\” as follows;
for fname in dirList:
videoList.add(path + “/” + fname)
I hope this is helpful to some of you who have been banging your head against the wall trying to figure out what was going wrong as I did for awhile.