• Media Player 20.11.2008

    The Java Media Player is back on track, and I have a Web Start Demo to prove it! The reason I haven’t blogged in a while is because I haven’t made much progress compared to the time spent. I didn’t have that many problems with making things work on the Mac, except for some window ordering problems that seems to be Mac related. But creating a version without problems that worked on both the Mac and on Windows was an exercise in mind control, Vulcan style. The process was like the old game on circus where you hit frogs with a stick. Hit one and it goes away, but another one pops up…

    The performance problem I reported in the last blog is all but gone. It’s not like the problem has been solved from Java’s side, I have just found a very narrow way around the problems. Let me explain.

    The problem was that turning a window translucent would absolutely kill performance on Windows, for reasons mentioned in the last blog. I initially made one window for all graphics but that was way too slow since it needed it to be translucent. I now have four (4!) windows and it will be at least five before I’m done.

    One window is the shadow for the main window. That window is also the main application window when you count the order and owner, strangely enough, but it had to be that way. Since the shadow should show the background though it is of course translucent. But since the graphics is almost never changed the performance isn’t that relevant.

    Both sidebar windows are now normal JDialogs, but undecorated of course. They have set the shadow window as the “owner” window since it needs to be on top of it. They don’t change size when they slide, that was too slow and jerky on the Mac, it is just the graphics in the window that slides. These are also translucent and paints their own shadow. The performance here is good enough since they don’t change too much, the number of pixels are quite small and I can have full control of the painting process and optimize it like a mad pixel pushing junkie.

    The main window is a normal window, but it is “shaped” on Windows and translucent on the Mac. This means that hardware acceleration will be in place for the main window, where it is most needed. You can see that it is a shaped window on Windows since the corners are pixelated. I do however have a sneaky way to solve this. I will paint the corners on the background shadow window instead, where we have translucency and thus anti aliased clipping/shapes.

    If you run the Web Start demo you can see the GUI in action. Or at least parts of it. Please don’t be disappointed, it is far far from ready yet, but I have made the critical things work, things that required performance to be “enough”. There are still a lot of optimizations left to do. For instance I don’t use Romain Guy’s much faster blur algorithm for calculating the shadows, I use the naive approach with Gaussian blur, which is quite slow.

    The app will need Java 1.6.0_10 on anything other than Mac. On OS X Java 1.5 is fine. I have not tested this on Linux, it will probably look like sh*t. ;) Anyway, most things are just mockups, feel free to click around.

    I will continue to update the app in place as I develop it and the same web start link will be used. Note that there are no media stuff in it at all, so don’t think it will play your mp3s, because it won’t. Yet… The app is signed with an old certificate so you will get a security warning. I will fix that when I get around to it.

    The size of the whole app is 180k, most of it images, and it is pack200 compressed. If you are on update 10 that “.pack.gz” file will be used, otherwise you will have a 400k jar instead…

    Well, enough babbling, just try it and let me know what you think. Is Java always ugly?

    Java Media Player Demo

    Mikael Grev

    Posted by mikaelgrev @ 12:15 am


  • 33 Responses

    • Soma Says:

      The main/side windows look ok on linux (no transparency though). Moving the main window around has some problems. The window does not move with the mouse, the side windows move correctly but the main window/shadow seems to have some random changing displacement… (see screenshot)

      your digital signature has an error (expired)
      Might be causing the “Java application window” on top of the windows (sometimes)

      screenshot (while dragging main window, see mouse cursor):

      multiple of these in the log:

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.miginfocom.a.a.f.a(Unknown Source)
      at com.miginfocom.a.b.J.(Unknown Source)
      at com.miginfocom.main.Main.a(Unknown Source)
      at com.miginfocom.main.a.run(Unknown Source)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
      Caused by: java.lang.IllegalArgumentException: The window must use a translucency-compatible graphics configuration
      at com.sun.awt.AWTUtilities.setWindowOpaque(AWTUtilities.java:376)
      … 16 more

    • Gregg Bolinger Says:

      Not bad. Running Ubuntu 8.10 and there is no translucency so looks pretty nasty. But definitely a good start.

    • mbien Says:

      wow, works great on widows with u10. Very smooth animations. If you manage to maintain this performance also with large datasets (e.g scrolling through media in tables) this will be my next media player ;)

      But I am not sure if windows users like to see mac design replicas on windows.

      looks funny on linux, you can even move windows between the tabs and te main window ;)

    • Sakuraba Says:

      Looks very nice. Moving the window feels a little bit sluggish on OSX, but very nice nevertheless.

    • Martin Wildam Says:

      Shadow, decoration or transparency of windows – I don’t need it. So why don’t you simply concentrate on playing the media?

    • Noemail Says:

      No transparency here either. Windows Vista

    • windowsuser Says:

      just for a quick run on winxp jdk 1.6.7:
      java.lang.ClassNotFoundException: com.sun.awt.AWTUtilities
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at com.miginfocom.a.a.f.a(Unknown Source)
      at com.miginfocom.a.b.J.(Unknown Source)
      at com.miginfocom.main.Main.a(Unknown Source)
      at com.miginfocom.main.a.run(Unknown Source)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)

      it looks nice but some other things look very disturbing…

    • JOKe Says:

      lol looks realy nice :)
      When it becomes stable and working I will start using this app :)

    • Pablo Says:

      Same here, using Hardy Heron with compiz enabled.

      Nice work by the way, the artwork component works just great.


    • Matt Nathan Says:

      Nice work, looks really good.

      I have noticed a couple of problems, one (which is quite cool anyway) is that when using Expose on a mac it separates out all the windows (shadow, side tabs, etc). Two the shadow for the side tabs seem to be on top of the main frame after retuning from expose.

      Apart from that it feels fairly responsive on an old (read slow) mac mini running java 1.5

    • Mikael Grev Says:

      Hello all above, and thanks for the kind words.

      Regarding loss of translucency and exceptions. That will happen if you don’t run it on 1.6.0_10, simply because Java outside OS X didn’t support translucency before u10.

      Yeah, haven’t actually tried expose. Good to know. Not sure what can be done about it though…

      Well, I don’t NEED it either. But it look more polished. Apple wouldn’t be so successful without the polish. And trust me, I intend for the usability to be as good as the app looks. :)

      Yeah, Java on OS X is very sluggish to move the windows for some reason. Not much to do, but I was surprised. That bug is in Apples hands…

      I have tested with, for instance, the number of tracks that can fit into my Mac’s 4BG memory and the table is running equally smooth. I will never give up before it is smooth, trust me. I’d rather not release it. :)

    • Gregg Bolinger Says:

      I am running it on 1.6.0_10 on Ubuntu. No transparency.

    • Nadav Steindler Says:

      Hi. I’m new to the blog, but I’m enjoying the interesting posts.

      If you’re getting performance problems with Swing, why not try SWT? As I understand, its supposed to be considerably faster since it uses platform-specific native widgets, as opposed to swing which is pure Java.

    • Collin Says:

      Looks very cool, and performance seems good on my laptop with integrated Intel graphics. Just one thing, there seems to be no task bar entry. Is there no JFrame involved here? I wonder if all the undecorated windows means no task bar entry.

      Also the JIDE common layer code has some interesting “Popup” related code which might inspire you in your quest for these slide out side panels.

    • Tom Says:

      The app looks great from a designerperspective (not taking personal taste into account). I still is a shame though that it takes that much hacks to get the i’s dotted.

      I’m very curious how far you can take this, especially on the performance part when real data is pushed around. (Dotting i’s again.)

      Good luck!

    • Mikael Grev Says:

      Strange. Then I guess that translucency isn’t supported on Ubuntu, or Linux in general? Or, it could be that you didn’t approve the app to run with full rights. Sun has made it so that the app needs to be trusted or that the user say he trust it in order for the translucency to work. Which is sensible actually. Is anyone having translucency in Linux?

      The fact that SWT is faster is both debatable (I have a GUI benchmark in MiG Layout that rates then as equally fast. SWT’s big advantage is that you get exactly the platform Look&Feel. SWT wouldn’t be an option anyway since I paint most of the stuff in plain Java2D, which SWT doesn’t have a replacement for.

      You are right about the JFrame. An oversight on my end. I will fix it. Just hoping not to see any new frogs when I do…

      Thanks. I will do my best. And yes, it is a shame that one need to be such an “Swing expert” to be able to do this kind of stuff. But I’m not sure there are any other cross platform GUI toolkits that does this much better…

    • Wolfgang Zitzelsberger Says:

      First of all your app looks really good.

      Because of the frame shadow workaround I wouldn’t do that because it causes to many problems which are typical for this kind of workarounds. Maybe it’s better to use pixel transparency provided by Java 6u10 by default and to add an option to disable transparency – so you can also provide good performance for older systems. This would prevent you from doing lots of hacks which are possibly hard to maintain. On modern Vista machines (with full Aero support) transparency works fine without any performance lacks because of hardware acceleration.

    • www.javanus.com/blogs Says:


      It look fantastic. Is it possible to get a source code?


    • Solerman Says:

      Linux do have translucency as long as one is using a composite manager. Compiz is one of those and is pretty much default this days (I wouldn’t use a desktop without something comparable). I think SWT isn’t a option for an application like this, it isn’t themable in its current version AFAIK. And if it gets themable, it will not be native, so what’t the point anyway?

    • mbien Says:

      >Is anyone having translucency in Linux?
      u10 out-of-the-box translucency never worked for me on ubuntu. (GeForce, latest proprietary driver, disabling compiz does not help too)

      The only technique which worked for me is via JNA (see demo: https://jna.dev.java.net/#demos)

      widgetfx has the same problem.

    • Michael Says:

      Works great on OSX! Never thought something like this is possible with Java! Really cool! :)

    • Mohamed Mekkawy Says:

      Very good work, works very good on ubuntu with a small issue the two side windows are always on top with a blank white page.

    • anonymous Says:

      this is awesome, but i think ‘ll make more sense if u open source it so everyone cal learn from it, i think thats part of the idea of a blog.

    • Mikael Grev Says:

      To have the whole main window transparent is simply not an option. You could not even have a single JTable in it since the selection was very very sluggish on XP/Vista.

      @Javanus, anonymous
      If I find a reason to make the extra effort that is needed to drive this as an Open Source project then maybe I will.

      I don’t know where you get that blogs and Open Source are related from.

      @Linux users
      Thanks for the info. I will make it more Linux compatible before release, which is not even near…

      Mikael Grev

    • John Tunnicliffe Says:

      Great work. Sluggish when moving the window is OSX, sometimes the side tabs come away from the main window when moving. The main screen and shadow come apart in Expose.

      Apart from that it looks great and I think we’d all love to see how it’s done by taking a peak at the code! Can’t wait to see more progress on this.

    • Olivier Gout Says:

      Looks great and promising !
      I can confirm the transparency problem with Linux (mandriva, java 6u10). If you decide to go further in the support for this OS, let us know how you plan to get it playing multimedia streams on this platform…

    • Soma Says:

      you might want to have a look at this substance l&f issue that had exactly the same frame dragging issue (mouse not sticking to the frame)


    • maxwell Says:

      Looks amazing… =)

      Great work, can you talk about the Look and Feel and Animations, are you using a “popular laf” or create your renders?

      For animations, are you using timing framework?

    • Mikael Grev Says:

      The Window movement jerkiness is OS X and Java, can’t work around it.

      Thanks! I am now using the Java 6 way if available. Can’t verify if it works better, but it should.

      I don’t use any L&F (or rather, it doesn’t matter). I only use my own Painter implementation to draw anything custom. It is crafted for my needs though and would not fit everyone.

      Timing Framework was a bit too limited, so I extended it a bit. Nothing too much but it had simple limitations about not being able to handle two animations targeting the same property in a good way.

    • Luca Says:

      Wow really impressive. The application rocks on 6u10, extremely fast animation. Using Java 7 i’ve got no transparency, but i supposed this is all java 7 fault(it’s still beta by the way).

    • Manuel Kaess Says:

      Your player looks very promising. I just finished my own media player applicaton using transparent windows (if available). My approach is using j6_u10 window transparency by reflection. So if it is available my player makes use of it, otherwise I stick to “regular” windows.

      You can take a look at the player here: http://www.impressive-artworx.de/albumplayer_en.php

    • Wolfgang Zitzelsberger Says:

      Hi Mikael,
      because of window opacity performance I opened a thread at the java2D forum. See http://forums.java.net/jive/thread.jspa?threadID=54761

    • mikaelgrev Says:

      Thanks Wolfgang,

      I made a small comment over there. It would be very good if they solved the problem since I could then skip all the funky tricks…