1

I'm using usbmount to mount / unmount USB drives when they are inserted / removed on my Raspbian machine. A C++ app reading MP3 files from the drive and playing them now needs to get a hint every time such a drive has been mounted (typically at /media/usb0) resp. unmounted.

Does anybody have a hint for me? Thank you.

0

One quick way would be to write a script that executes usbmount on a given drive, as well as updates another data/text file, that the C++ app could poll for changes based on some time interval. Another method would be to simply include a call to your C++ app after you execute usbmount.

Is your C++ app set to immediately autoplay files found on a given mounted USB? This might be a can of worms without very diligent input file filtering.

  • Well, not immediately, but it's gonna play MP3 files from a stick (non-MP3 files will be excluded with a simple glob ()). Sure I can wait for a couple of seconds, but as for now, I've gotta insert the stick before launching the app, which is not feasible once the app is in production. – Neppomuk Mar 2 at 18:26
  • Is this suppose to only be used for usb drives with specific directory structure, or once usb is inserted the app will search for any and all mp3 files on the usb device. Please clarify, the app's relatonship with the Raspberry machine. Is it a standalone app on a phone, or computer that makes a remote connection to the raspberry, or something running strictly on the raspbian as a script? – BarBar1234 Mar 2 at 18:53
  • No, the app runs locally on the Raspi and nowhere else. The stick, of course, is attached directly to the Raspi. The app will find all MP3 files residing on the stick, no matter in which directory they are. – Neppomuk Mar 2 at 22:24
  • Can't the app simply poll at a 3s interval the path /media/usb0 path, and if any files are found, it can proceed to the search for mp3 files. and If the media/usb0 path is empty break for another 3 seconds and so on. Or better yet you can modify a udev rule to watch for new usb devices. – BarBar1234 Mar 2 at 22:59

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.