Quality code and lots of coffee

Category: Article (Page 2 of 2)

Raspberry Pi – Media Player

I recently took the plunge and bought a Raspberry Pi to replace my tired and decrepit old Dell Server. The main purpose of which was to hook it up to an external hard drive, leave it plugged into my TV and watch some movies on it. Basically a torrent/video box with maybe some web hosting thrown into the mix.

So the pi works out the box with NOOBS and I went straight for Raspbian as I preferred the Debian based system. However when I started with the machine it became apparent that there is actually a problem with playing videos…

The Pi isn’t a powerful computer, and as such has problems playing videos outside of specific environments such as XBMC, and since I wanted to stay away from dual boots I thought I better make it work. I tried a few solutions like VLC and Gnome-MPlayer but the hardware platform made videos a bit difficult, there was only one application that worked, OMXPlayer.

OMX is a command line video player (which sounded redundant from the start) and when I ran the command to open a video it seemed to work audio and video perfectly, however using the command line for everything is not my style, I was quite happy to keep using OXM but I was more in the mood for a double click and play situation.

Luckily I found a forum post (X) that showed me just what I was after, you can create a symbolic shortcut to OXMplayer that you can launch from the menu, and you can add an argument into the command so that you can pass a file path with a double click of the file.

First of all you need to open up a terminal and enter the following command to create the shortcut.

sudo nano /usr/share/applications/oxmplayer.desktop

then paste in the following lines

[Desktop Entry]
Type=Application
Name=OMXPlayer
Categories=AudioVideo;Player;
Exec=lxterminal –command “omxplayer -o hdmi %f”
Terminal=false
Icon=/usr/share/icons/nuoveXT2/96x96/categories/applications-multimedia.png

Use CTRL+X to save the shortcut and when closed there should be a new item in your menu showing OMXplayer

OMX Player Shortcut

Double clicking this item will not do much as there is no file to actually play, however you can change the default player of video files to use this application using by right clicking a video and pointing to this shortcut.

OMX Default Player

You can now double click on a video and it will launch in OMXPlayer command line.

There is however further problems, specifically to do with resolutions, because unfortunately for some reason if the video doesn’t match your monitor resolution you will end up with bars on the sides of the screen

Philadelphia

as you can see in the picture the sides are still visible because unfortunately earlier episodes of Sunny in Philadelphia wasn’t shot in widescreen. The video is already running as large as we can, but we need to find some way to blacken the screen.

Checking the man options for OMXplayer I found that by adding the -b argument to OMXPlayer it will black the edges of the screen for you to make video time a bit better.

Some people have indicated that there are issues with the screen refreshing or not coming back on after a video which was discussed in this bug.

So to make the screen blackout during your video change the following

[Desktop Entry]
Type=Application
Name=OMXPlayer
Categories=AudioVideo;Player;
Exec=lxterminal –command “omxplayer -b -o hdmi %f
Terminal=false
Icon=/usr/share/icons/nuoveXT2/96x96/categories/applications-multimedia.png

and that should do it easy videos.

Since the OMXPlayer is in command line there is no GUI so here is a helpful list of how to actually control the player here

Who the hell is Mark?

A few days ago I was sitting at my computer as I do and saw this in windows explorer…

Active Directory

I was a little confused, I live alone and only have a handful of devices connected to the internet, none of them called mark.

I checked my DHCP and found nothing, just me and my phone online.

I remembered that I recently connected to the work VPN and maybe windows was remembering some of the devices I was connected to, one of the guys in Infra is called Mark, so it was probably his laptop and windows was just remembering it, at the very least nobody was on my network… right?

So a day goes by. I notice again in windows explorer, my laptop is not online, but my PC and Mark are, not only is Mark still connected to my network, but I know for sure my network has refreshed recently. The plot thickens!

I again checked my router, no other devices connected.

A week or so goes by, my network keeps playing up, having dropouts, devices not connecting to one another general laggy behaviour, Mark is still there.

One day I’m playing CS:GO and my connection drops out, third time this week. I go to check my router settings. Type in username and password “This password is incorrect”. Try it again, “This password is incorrect” I double check the IP to make sure I’m still in the right place. Then it hits me; my router doesn’t ask for a username, just a password.

I was seeing this:

Login Screen

But should have been seeing this:

My usual login screen

My usual login screen

I checked on my phone, connected to my router first time. Checked the DHCP and noticed something odd. I wasn’t there. My PC just was not connected to my network. So I thought I would check, and lo and behold

My IP difference

My PC and the rest of my devices were on 2 separate networks. So what’s the difference, well my PC has a wired connection but instead of connecting direct I use powerline adapters, articularly I have these powerline adapters. Powerline adapters use your homes internal wiring to transmit data packets around the place, as to not interfere with regular electricity they broadcast on different frequencies.

So I thought, what if a neighbour has the same adapters I have, or ones using the same frequency. The connection at my end wouldn’t know who it was paired with, it would connect to both or switch between them depending on who it decided to pair with. Now it made sense, the slow internet, the timeouts wasn’t my service being shit. I was connecting to another network altogether!

I decided to conclude my findings, on this new network I decided to have a bash at their router password, most people aren’t me and don’t change their default password, and since it was a Virgin Router I knew what that’d be. Unsurprisingly I gained access straight away, went to their DHCP page and would you believe it

Marks Router Settings

Mark was never stealing my internet, I was stealing his! it also meant, more worryingly, that the electricity in my house was not a self contained network, the sockets on my PC are somehow connected to another houses power supply.

I was so impressed by this problem I thought I would share it, as I’m simply fascinated such a problem could exist.

Retro Graphics Engine

As part of the ongoing improvements to my text based adventure game, I decided to develop a retro style graphics engine to go with the text based aspect.

This meant having to upgrade the Console Application I had developed into a Windows Application without having to do a major rewrite of the engine; I did by creating methods which would complete the same job as the original Console method, but using a form instead of a console.

The central idea I had for my graphics engine would be to add a new string parameter to some data types and store the relative path to an image for that item. This would mean having to keep all the images in the file system with the game, so hopefully we can keep the size down.
Since I have moved the player command interface from a never ending loop to a regular method with a string input (so the UI remains responsive) I simply added a new method at the footer of the player input which triggers a drawing of the room.

The drawing method starts by checking if the Room/Building has a background image, then paints a panel with that image. If there is no image then it retains the previous. Then the method iterates through every item, enemy and NPC, and for every one of those items that has a valid image, it creates a picturebox element and adds it as a control to the panel.

Through this simplicity the game was able to build environments quite dynamically, when items are picked up or enemies killed the environment was updated.
The biggest issue I had was with placement, originally thought that I would pre-define some locations and the game would just place whatever data item at that place, however this meant that there could only be a finite number of images on the screen, and that no matter what the screen the images would always appear in the same place, which would not always make sense.

So I decided I could actually incorporate image painting into the world editor. If I extended the room editor form with a similar panel I could draw the room, and all I would need to do would be to add functionality to the PictureBox elements to be able to position them, then when the room is saved to scan through the locations of the panel, and assign the Location attribute of the PictureBox back to the data item. For this I had to add a Point attribute to the data items, and that meant having to add in System.Windows.Drawing reference to the project.

So originally I designed that when each picturebox was made, it had a mousemove method which would reposition the picturebox to the position of the mouse
public void DragNDrop_MouseUp(object sender, MouseEventArgs e)
{
PictureBox picBox = (PictureBox)sender;
if (e.Button == MouseButtons.Left)
{
picBox .Location = new Point(e.X, e.Y);
}
}

However there was a problem. The mouse event argument “e” had both X and Y attributes which held coodinates relative to that control. So when I started to move the control it would send the coodinates from within the panel, which would move the picturebox to the mouse location within the panel. But when the cursor was inside the picturebox the coodinates would be sent from within that control so all at once the picturebox was being sent coodinates to within the panel, and from within itself, but in both cases was being moved within the panel. Obviously this was a problem.

The solution, was to not use the global coodinates of the MouseEventArgs. It also passes in a Location attribute, which holds how far the mouse has moved in the X and Y axis. This meant that we could figure out the new position of the PictureBox if we took how far the mouse had moved and added it onto the original position, as below
public void DragNDrop_MouseUp(object sender, MouseEventArgs e)
{
PictureBox picBox = (PictureBox)sender;
if (e.Button == MouseButtons.Left)
{
int X = picBox.Location.X + e.Location.X;
int Y = picBox.Location.Y + e.Location.Y;

picBox.Location = new Point(X, Y);
}
}

This meant that the world designer would now draw the the room, and the user could paint it as they saw fit, and on saving the game would save the location of the data item so when the game is played, the environment was presented in a much more suitable fashion.

There is still an issue of items being carried. Default items in the inventory will not store Point data, and when an item is picked up and dropped in another room it will retain it’s original position, which may not always make sense but one step at a time.

Newer posts »

© 2025 Joe van de Bilt

Theme by Anders NorenUp ↑