craighissett
Posts: 10
Joined: Fri Oct 03, 2014 10:12 pm

Python Video Playing - Advice

Thu Jun 25, 2015 1:00 pm

Hi all
I am currently working on a Pi-based video player for my son.
I am hoping to use python to achieve this, however I am looking for advice (I have never undertaken a project like this before).
The device itself will feature a small screen, and 9 buttons:
  • [1 x Play/Pause]
    [2 x Prev/Next]
    [6 x Playlist]
Each playlist button is going to represent his favourite characters; Peppa Pig, Barney The Dinosaur et al.
When playlist button is pressed the player will start playing that characters set of videos. These videos are to be sourced from many locations (there may be 2 or 3 storage devices attached with content) so one singular playlist of each one would be beneficial. I am thinking of compiling the playlists on startup. For example, for Peppa Pig, all videos across all storage would be saved in a folder called 'PeppaPig'. The playlist would list all the files within each of the Peppa Pig folders in one big list.

What I am hoping to achieve is a python script (ran on startup) to do the following:
  • [Load a splash screen image (a loading screen while playlists are being compiled)]
    [Find all folders on all attached storage matching a Playlist name variable and compile one big text file of the locations of the files within the folders]
    [Repeat for all 6 playlists the player will use - I may store the playlist variable (PeppaPig, FiremanSam etc) in a text file and pull from there; allows playlists to be edited easily without having to change the code]
    [Use the text file to provide file locations to the video playing element of the script]
    [Monitor a serial port for commands to trigger playback/playlist changes from an Arduino handling button presses]

Has anyone got any experiences with any particular libraries and as such would recommend?

Here is a link to the Hackaday page where i am planning my build:
https://hackaday.io/project/5700-pi-video-player

And here's a link to my dropbox, where I shall be storing any plan or design files:
https://www.dropbox.com/sh/zutwgvtk53wq ... -GS3a?dl=0

Thank you for any help you can offer!

Craig

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Python Video Playing - Advice

Thu Jun 25, 2015 1:42 pm

I love the sound of this project. I did something vaguely similar here.

I don't see anything in your code that shouldn't be possible to achieve in python.

Taking your points in turn, my thoughts are as follows:
  • [Load a splash screen image (a loading screen while playlists are being compiled)] I've used pygame to do this before. May be overkill for this though.
  • [Find all folders on all attached storage matching a Playlist name variable and compile one big text file of the locations of the files within the folders] There are various ways of doing this with the os module. Have a look at this question on stack overflow for starters.
  • [Repeat for all 6 playlists the player will use - I may store the playlist variable (PeppaPig, FiremanSam etc) in a text file and pull from there; allows playlists to be edited easily without having to change the code] As above.
  • [Use the text file to provide file locations to the video playing element of the script] You could use the configparser module or just have a raw text file and parse that yourself in your script.
  • [Monitor a serial port for commands to trigger playback/playlist changes from an Arduino handling button presses] Any reason that you need an arduino to handle button presses? Why not use the GPIO pins on the Pi? I didn't see anything that suggests all the pins are being used
Other people may have different suggestions but I'm happy to provide any help where I can.

Have fun and I hope you enjoy the build!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

craighissett
Posts: 10
Joined: Fri Oct 03, 2014 10:12 pm

Re: Python Video Playing - Advice

Thu Jun 25, 2015 2:22 pm

elParaguayo wrote:I love the sound of this project. I did something vaguely similar here.
Ah, elParaguayo! Thank you very much for providing those links; your project does look very similar to what I am trying to achieve.
Regarding the use of the Arduino: It it/was more of a comfort thing. I started using the Arduino in projects long before I picked up a Pi so i feel more comfortable using one. I had also read a few posts saying caution needs to be used when connecting to GPIOs etc. I may well use your project as a guide and attach my buttons direct to those GPIOs. Removing the Arduino means one less thing to power, so good times! :-)

Thanks for stepping through my points; on my dropbox I have a Word document in which i am compiing all thoughts and sample codes ideas until i can piece together some code. Hopefully it will make my ramblings a bit more clear for you good people, ha ha!

For the splash screen i was thinking PyGame; I had contemplated TKinter, however in the future i may well like to add more complex imagery/animations to keep my son engaged so it would be great to start with the more powerful library.

I had read that it is possible to extract text from txt files, so I think I am going to use text files for saving both the playlist folder names (to be parsed and used as variables in the code) and the playlists themselves (to be used the same way).

Just had a quick look at your GitHub for your project and I like how you have broken out the various elements into their own .py files; I have always thought about approaching this as a single Python script but it makes much more sense to do it like this. I must start a Github repository for this!

Thanks again for the offer of assistance - it's greatly appreciated! With a little bit of prodding in the right direction and some input from more experienced folk such as yourself I reckon I could have a great build on my hands; I have been lucky enough to have some help with the 3D design of it via Hackaday.io members so this is definitely an international group effort ha ha!

Craig

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Python Video Playing - Advice

Thu Jun 25, 2015 2:36 pm

Craig,

Splitting out bits of code into separate files can make things far more manageable (my code would have been a very long file if I didn't do that).

The project I linked to is also modular in that I can add "modes" to the box (e.g. to play a different sound set). The same principle could apply here, e.g. instead of hardcoding 6 buttons to 6 playlists, you could have a menu of different playlists and then scroll up and down and select to play. It's up to you, there's a lot to be said for having fixed modes (especially if your button has a Peppa Pig sticker on it for example), but if you think you may have more playlists than buttons then it's worth considering.

On the GPIOs, I wouldn't be too afraid of using them you just need to make sure that you're using pull-up/down resistors and it should be pretty straightforward. If I get the chance I'll try and find a diagram of how my project is wired.

In terms of using a text file, the configparser can take some of the effort out of parsing your text file. That said, it's not essential and it's a good skill to learn how to read and parse files yourself.

The biggest issue I had with my project was my son constantly asking "Is it ready yet, Dad?". However, once it is finished and you see the fun they have playing with it then all the long hours, swearing etc that went into the build are quickly forgotten!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

craighissett
Posts: 10
Joined: Fri Oct 03, 2014 10:12 pm

Re: Python Video Playing - Advice

Thu Jun 25, 2015 3:58 pm

Thanks buddy

I definitely see the advantage in breaking it down; I think half of my 'fear' of coding this one is the potential amount of coding. Breaking it down would allow me to tackle it one section as a time.

Love the idea of different modes - I could use that to add banks of playlists in the future, somehow.
I also like the idea of using a menu to scroll through. I had originally planned to add stickers around the buttons for my son to associate to a particular playlist, but maybe that is something I can replicate in PyGame? I could have an image in the corners and on the sides of the screen next to the buttons; the previous/next video buttons could allow him to scroll through banks too.
At present I will just need the one set of 6, but it would definitely be great to allow it to grow as he does.
I'm open to suggestions on that one!

configparser looks great. I see it can be used to process .csv files, which may be better to use rather than plain text.

Thanks for the GPIO tips buddy - what size resistor do you recommend? I'm sure I'll have some lying around that I can use. I will try and get some soldered up tomorrow on my lunchbreak at work!

The joy of this project is neither my son or my missus know about it, so I can build it pressure free :-)

Oh, I have now started a GitHub for it here:

https://github.com/CraigHissett/PiVidPlayer

At present just sounding out some idea of structure in the Readme.md, and listing some functions i may have to cater for.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Python Video Playing - Advice

Thu Jun 25, 2015 4:28 pm

craighissett wrote: I also like the idea of using a menu to scroll through. I had originally planned to add stickers around the buttons for my son to associate to a particular playlist, but maybe that is something I can replicate in PyGame? I could have an image in the corners and on the sides of the screen next to the buttons; the previous/next video buttons could allow him to scroll through banks too.
At present I will just need the one set of 6, but it would definitely be great to allow it to grow as he does.
I'm open to suggestions on that one!
One of the great things about all this is that the project can evolve and anything you do now can be changed. For that reason, you may want to start with the 6 fixed playlists just to remove a layer of complexity from your project for now. Once you've become a python guru then you can come back and think about updating it to something different (unless your son loves it as it is)!

As for the size of resistors, I think just went with what's on this page: https://www.cl.cam.ac.uk/projects/raspb ... _switches/

Another piece of advice, and I think you've already got this, is to break down the project into lots of separate bits and get each of those bits working on their own (making sure you understand why they work) and, only once you're comfortable with those bits, pulling them together into your master project.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

craighissett
Posts: 10
Joined: Fri Oct 03, 2014 10:12 pm

Re: Python Video Playing - Advice

Thu Jun 25, 2015 4:52 pm

Thanks man - I agree with you there.

I will stick to the 6 fixed and then see where I go from there :-)

That link is great, thank you - even I should be able to follow that guide ha ha!. I think I have both of those resistor values kicking about so I will aim to have something knocked up tomorrow to take home from work to start working with it.

Definitely got the message regarding breaking it down :-)
I'm going to create a script to handle playlist compiling, one for button monitoring, one for video playing and one for the GUI side of things, then combine them all once each element is working.

Craig

craighissett
Posts: 10
Joined: Fri Oct 03, 2014 10:12 pm

Re: Python Video Playing - Advice

Tue Jun 30, 2015 4:55 pm

Just a quick little update:

I've had a little dabble with getting some of the Python coding done for this project, as the hardware has taken a big step closer to actually working :-)
So far I have started working on what will be the Playlist class; at present I have created a function which outputs a list of file locations to a text file for reading by the video playing part of the code.

Next step is to create a function for listing all drives attached to the machine it is ran on, then step through each one looking for folders containing the playlist name, before conducting the output.

Once I have code which i can pass the 6 playlist names to and handle the rest itself I will be very happy!

Return to “Python”