1

I have "video player" with OMXC in Python.

Something like THIS

Video file "1.mp4" is on USB stick and commands in Python:

movie1 = ("/media/pi/USBSTICK/1.mp4")

omxc = Popen(['omxplayer', '-b',movie1])

are working. But when I eject USB stick from Raspberry and put in to computer with Windows (for example when I want to change to another video 1.mp4) and put back to Raspberry, isn't working.

When I checked folders in Raspbian, folder /media/pi/USBSTICK is empty and new folder with video /media/pi/USBSTICK1 was created. Raspbian add index "1" for USBSTICK. When I try to made again, new folder was created with name USBSTICK2 and my program in Python can't find video file 1.mp4 in right folder.

I think isn't problem with Python and OMXC, but with mounting USB stick in Raspbian. I guess that problem is when USB stick is unplugged without unmounting. It happens when power supply colabs and Raspbian isn't turn off correctly.

It's possible to set up something like "unmounting empty folders" after rebooting?

Thanks!

Code:

import os
import sys from subprocess
import Popen from omxplayer
import OMXPlayer

movie1 = ("/media/pi/USBSTICK/1.mp4")

while True:
            os.system('killall omxplayer.bin')
            omxc = Popen(['omxplayer', '-b', movie1])
            omxc.wait()
  • 2
    I think, it might be a problem with the code you use to mount your USB drive. Would you please include that code into your question as well? – Fantilein1990 Nov 22 '16 at 14:03
  • Doesn't sound like you're unmounting your USB disk when you remove it. So the Pi just creates teh next drive in the list by adding a "1" to it. Is there a reason for doing your eject that way? – dbmitch Nov 22 '16 at 18:39
  • @Fantilein1990 How you mount it doesn't really matter; what is important is to properly unmount the USB stick before one yanks it out. His code should probably include a function to unmount the stick upon command. – JvO Nov 22 '16 at 18:57
  • Reason for this untipically beahviour is when the power supply system failed. The RPi isn't shutdown correctly and USB stick isn't unmounted correctly too. – Waldik Nov 27 '16 at 20:00
1

As @dbmitch and @JvO pointed out, your problem is most likely caused by not correctly unmounting the drive.

Using the terminal, you would need to enter

sudo umount /media/pi/USBSTICK

to unmount a USB drive.

In python, you could insert that command into the os.system()-method. The easiest - though not most elegant way - to include that into your python script would be to mount the drive as first command in your while-loop and to unmount it as the last command in your while-loop:

while True:
        os.system('sudo mount /dev/<yourDevice> /media/pi/USBSTICK')
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-b', movie1])
        omxc.wait()
        os.system('sudo umount /media/pi/USBSTICK')

The should be something like sda1 - a kind of pointer to the physical USB drive. You can find out what to insert in your case by comparing the results of the terminal command sudo blkid before and after inserting the drive.


Update: In Linux, mounting something works a little bit different from what is happening on Windows systems - at least from a user's perspective. The mount location (in your case /media/pi/USBSTICK) is a directory (aka folder) like any other (e.g. /home/pi/yourStuff or /etc/ or /var/). Whenever you mount a device, the device's file system becomes inserted into that directory - and whenever you unmount said device, the (empty) directory stays behind. You can allways remount it to that location again - provided, the directory is still empty (meaning nothing inside and nothing mounted to it).

| improve this answer | |
  • But when the USB stick is out of Raspberry, folder USBSTICK in /media/pi is still. When I try to unmout with command: umount /media/pi/USBSTICK response is "not mounted". Raspberry restarting is without effect, folder USBSTICK is still in /media/pi. – Waldik Nov 27 '16 at 18:36
  • Updated my answer, I hope this makes it clearer now. Your system is behaving exactly the way it should - at least from what you are describing :-) – Fantilein1990 Nov 28 '16 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.