Skip to content

Unexpected LaTeX!

Somehow I forgot to mention that as well as delving into the world of C# I’m just finishing up my PhD thesis.  Having experienced the horrors of trying to manage a large document in Word, I set about learning to use LaTeX, which for this kind of work is superior in just about every imaginable way.

Once you decide on a style sheet, LaTeX pretty much manages everything for you, and lays it all out beautifully.  When it works, it works sublimely.  When it doesn’t work, you can really end up stuck.

So, I’m going to post a bunch of LaTeX problems too, since it can be really hard to find solutions when you don’t know the right vocabulary.

Mouse events on DirectX.AudioVideoPlayback Controls

This is the issue that finally pushed me over the edge to setting up this blog.  Normally when you have a coding problem, you find the answer fairly quickly and move on.  Sometimes though, the solution remains elusive.  Then you put the answer on a page of your own, to help out the next weary traveler.

Which bring me neatly to…

AudioVideoPlayback

I recently posted my lightweight media viewer, Picsie.  As well as images, it also handles some formats of videos.  The video playback was largely on a whim when I stumbled across the wonders of Microsoft.DirectX.AudioVideoPlayback.  The code to set it up and use it is endearingly simple:

Microsoft.DirectX.AudioVideoPlayback.Video videoPlayer
	= new Microsoft.DirectX.AudioVideoPlayback.Video(filename);
videoPlayer.Owner = videoPanel;
videoPlayer.Play();

Give it a video file and a control to draw on, and tell it to start.  Some form of error handling is probably wise too.

All well and good so far.  A few buttons to control playback, and you’ve got a basic but functional video player.  My problem came when I wanted the video to have the same control system as the rest of Picsie – left-double-click to centre, right-click to exit, drag to move.  These all worked for images, but when I came to test it on videos, only the drag code seemed to work.

It was pretty simple to diagnose.  MouseDown, MouseMove and MousePress all continued to function as before.  For reasons unknown, the Video object ate any Click, MouseClick, DoubleClick and MouseDoubleClick events.

At this point the Internet failed me.  No solutions, and I had two features no longer working:

  • Right-click to exit
  • Double-click to centre

Not able to find a way to get my events back, it was fairly trivial, if a little messy, to move the right-click code to the MouseUp event, with a little jiggery pokery to make sure it was a click and not a drag.  On the other hand, did I really want to write all the code to check for and handle double clicks myself?  No, no I didn’t.  Thankfully, I didn’t have to.  MouseEventArgs has a “Clicks” property (when did that appear, and why did nobody tell me?), which you can use to fake a double-click event:

private void Panel_MouseDown(object sender, MouseEventArgs e)
{
	if (e.Button == MouseButtons.Left && e.Clicks == 2) {
		//Double-click
	}
}

And there you go.  I never did find out why the Video object ate my events.  There’s probably a really simple solution somewhere, or I did something boneheaded, but more than one person faced this problem and never found an answer, so here’s mine.  Fake clicks and double-clicks.

tldr/

Problem: AudioVideoPlayback.Video eats MouseClick and MouseDoubleClick events.

Solution: Check for double-clicks using the MouseEventArgs “Clicks” property in the MouseDown/MouseUp events which aren’t eaten.

Picsie

Picsie is a very lightweight image and video viewer, with an emphasis on speed and minimal interface.   I primarily made it because while in the past I was perfectly happy with XnView, Quick Look on the Mac made it obvious how much Windows was missing something similar.

A while later I saw VJPEG which did pretty much exactly what I wanted.  Unfortunately it lacks a few features I like, so I set about making my own.

The result is Picsie.  It opens .bmp, .gif (including animated GIFs), .jpg, .jpe, .jpeg, .png, .if, .tiff, .avi, .mpg and .wmv files.  There is essentially no UI to it – simply a picture (or movie) on your desktop, with a drop shadow if your version of Windows supports it.  If it’s larger than your screen, it will be scaled to fit.  If you move away from the window, it will fade slightly.

Controls are entirely mouse and keyboard:

  • Drag: Move the window
  • Right click: Exit
  • Mouse wheel: Zoom
  • Double-click: Centre and zoom 1:1
  • Escape: Exit
  • ‘t’: Toggle whether or not Picsie stays on top of other windows
  • ‘b’ / ‘f’: Toggle fading if application loses focus
  • ‘h’ / F1 / ‘?’: Show this help page

File browsing:

  • Left arrow: Load previous file in folder
  • Right arrow: Load next file in folder
  • Up arrow: Load first file in folder
  • Down Arrow: Load last file in folder

Animated GIFs:

  • ’0′ (Zero): Pause animation
  • ‘-’: Reduce animation speed
  • ‘+’ / ‘=’: Increase animation speed
  • Backspace: Reset animation speed
  • ‘[': Step frame backwards
  • ']‘: Step frame forwards

Video Files:

  • Space: Pause/Play video
  • ‘m’: Toggle sound

If you use the installer (see the bottom of this post) it will set up your file associations for you.  It plays nicely with other applications and just adds itself to the list of programs which can handle the file formats, rather than overriding everything.

If you load a large file (more than 10MB) Picsie prompts you rather than loading it immediately.  In this case you will get a message telling you to press return to view the file.

Lastly, if you open a corrupted or invalid file, or Picsie just has a problem (temperamental beast that it is), you’ll get an error message.  Feel free to complain at that point.

Downloads – Alpha 1.9 (6 April 2011)

  • Installer (~75KB).  This will set up your file associations for you.
  • Standalone .exe (~200KB).  Use this if you already have Picsie installed and you just want the latest version.  Just drop it over the existing one.

Changelog

Alpha 1.9 (6 April 2011)

  • Added tooltips for images.

Alpha 1.8 (30 November 2010)

  • Now properly releases animated GIFs when you switch to a different image.

Alpha 1.7 (18 November 2010)

  • Has a taskbar icon in Windows 7

Alpha 1.6 (13 October 2010)

  • Fix: Sets the zoom level properly when you load an image
  • Fix: Now consistently applies the minimum zoom level

Alpha 1.5 (26 September 2010)

  • Fix: Set a minimum size that you can zoom out to, rather than a minimum zoom level.
  • Fix: Animation speed for GIFs is now read from the file, so should match what you see in other viewers.

Alpha 1.4 (4 September 2010)

  • Fix: Picsie’s maximum zoom now hits the limits of the screen, rather than falling short.  This also stops the stretching effect when the limit was reached.

Alpha 1.3 (7 July 2010)

  • New: If a new Picsie window is the only one loaded, it centres on the screen.  If a window already exists, it loads wherever Windows puts it.  This significantly helps with the layout and ease of use as you always know where the first one goes, and additional windows don’t appear directly over it

Alpha 1.2 (20 June 2010)

  • Fixed: Mute setting wasn’t remembered between videos
  • Fixed: Refuses to load files with extensions not in lower case (e.g. image.JPG)

Alpha 1.1 (15 June 2010)

  • Fixed a bug in the installer that stopped Start Menu icons being created in  Windows XP

Comments, Feedback and Such

If you have any comments, suggestions or bugs, email me at andy@aburn.org.uk to let me know.  I’ll gladly look into any feature requests, and do my best to address any bugs.

Things to Look Out For

  • At this stage it would be useful to know how the installation process goes on other computers.  Does it install OK?  Do the file associations get set up properly?  Inquiring minds need to know.
  • Does it ever just fall over completely on some files?
  • Does it handle large files nicely?

If anything in that list gives you a problem, let me know and I’ll deal with it ASAP.

Licenses and Thanks

The icon used is from the wonderfully talented Kuswanto at Zeus Box  Studio.

Picsie is freeware, so feel free to downoad it, hand it around, share it, whatever.  I’ll be open-sourcing it sometime in the near future, once I get around to it.  Until then, all copyright on the software is mine.



A bit about me…

It’s a familiar story – I started programming when I was really young and never stopped.  My dad had a Dragon 32 – not the most ancient of computers, but pretty old by anyone’s standards – and let me play on it.  The idea of a toy that didn’t do anything by itself was pretty novel, and I set about learning how it all worked.  As I said, a pretty typical story for a software developer.

Skip forward 20-odd years, past the Spectrum, more PCs than I care to count, and two Macs, past Basic, Pascal, Delphi, a bit of web development and a plethora of languages I poked at university, and we arrive at Java and C#.  C# for preference.

My degree is in AI, but I spent several years teaching first years Java, then moved onto being a real scientist.  An actual Computer Scientist, rather than a developer.  Evidence-Based Software Engineering is a growing field, and will hopefully influence any and all aspects of software engineering, from agile methods to unit testing, to education.  I urge you to have a look at the website, and cringe at how little evidence we actually have on which to base technical and managerial decisions.

Back on topic, I’m finally moving into the real world, as a C# developer, so you can probably expect this blog’s subject matter to become more enterprisey as time goes by.

The vast majority of problems I’ll be documenting (and posing, when the Internet fails me, as is its wont) come from personal projects, which I’ll also be posting when I think they’re ready for public consumption – basically once they’re past the point of mockery :-)

My most recent project, a lightweight media browser (I know!  How innovative!  Trust me, I made it because I needed it), has spawned half a dozen possible posts, so expect more on that just as soon as I’ve found a name for it.

Just what the world needs…

Another blog.  About programming, no less, because there aren’t many of those on the Internet.

I’ve been intending to start this up for a while now, so now that I’m desperately rushing to finish my PhD, about to start a new job and trying to find time to finish and publish a two-year long case study on unit testing (woo, indeed), it seemed a logical time to start a new commitment.

In short, this blog is like many others, a place for me to put programming problems and solutions that had me scouring the web and picking people’s brains.  So, whenever I eventually find/invent/kludge a solution to a problem, it goes here, with examples, source code and downloads.

And if  I get enough of them then maybe, just maybe, the next person won’t have to search so hard.