I have written a media player using VLCj;
And I am trying to replicate VLC player, so that when the space key is pressed, the word "Play" will briefly appear on the screen. Is this possible?
How would I go about showings this temporary overlay?
One way to do this with vlcj is to use the "marquee".
The marquee is provided by native LibVLC library functions, wrapped by vlcj.
First:
import static uk.co.caprica.vlcj.player.Marquee.marquee;
Then in your mouse click listener:
marquee()
.text("Play")
.location(x, y)
.position(libvlc_marquee_position_e.bottom)
.opacity(0.7f)
.colour(Color.white)
.timeout(5000)
.size(20)
.apply(mediaPlayer);
This is a "builder" style of API, there is another API with individual methods for the marquee, e.g.:
mediaPlayer.setMarqueeText("Play");
mediaPlayer.setMarqueeSize(60);
mediaPlayer.setMarqueeOpacity(70);
mediaPlayer.setMarqueeColour(Color.green);
mediaPlayer.setMarqueeTimeout(3000);
mediaPlayer.setMarqueeLocation(300, 400);
mediaPlayer.enableMarquee(true)
All of this is documented in the vlcj Javadoc:
http://caprica.github.io/vlcj/javadoc/3.0.0/uk/co/caprica/vlcj/player/Marquee.html
http://caprica.github.io/vlcj/javadoc/3.0.0/uk/co/caprica/vlcj/player/MediaPlayer.html
There are other ways...
You can try overlaying an AWT Label with absolute positioning on top of the video, this will work but the label will not have a transparent background.
You can use the so-called "direct" rendering media player (where you render the video yourself) and then you can paint your own graphics on top of the video, or use a Swing JLabel. In this case you can use transparency.
You could even overlay a transparent top-level window on top of your video window and paint/put your label in that window.
All of these approaches are demonstrated in the various examples in the vlcj test sources. There are test examples for marquee, and lightweight and heavyweight overlays.
But using the marquee is the simplest and therefore recommended way.
Related
I'm doing this project using Swing.
To add a more welcoming feel to the UI, I'm also adding a few Photoshopped images as the background.Here's where the problem begins...
I want the images to automatically resize themselves once the size of the window is increased or decreased, how can I make this happen ?
One way is to override the paintComponent(...) method of a JPanel to paint the image using the drawImage(....) method.
Another option is use a JLabel with an Icon as the background for the frame. Then you can use the Stretch Icon which will automatically scale based on the space available to the label. This is the most flexible solution since the StretchIcon can be used on any component that supports icons.
You can also check out the Background Panel which allows you to display an image. You can display the image at its actual size, scaled or tiled.
What are the differences between using a Canvas control or a Label control for drawing an image?
Both controls seem to have similar capabilities in terms of drawing images onto their displayable area, and can both use PaintListeners to further customize the act. I have always assumed that Canvases are more suited for the purpose than labels simply due to their name, but I cannot determine the actual practical differences. In what scenarios would you use one over the other for loading an image file and painting the image onto the control?
The Label inherits its drawing capabilities from Control, as well as many of the features in Canvas. But Canvas was built with extra controls for images, like dynamic drawing, buffering and partial update.
Summing up, it is ok to use labels for static small images, but when it comes to heavy-duty use, a canvas is more appropriate.
I want to create a tile editor sort of program where I have a viewport for rendering on the left side of the program, and then a panel of buttons on the right to use for opening files, saving the tiles etc... I was going to use LWJGL to do this, but it seems theres no good way to do it.
Essentially I guess I'm asking, how do I have a viewport for rendering using g.DrawImage or something, and then also have a panel of buttons next to that viewport?
You can do this using jME3 as they support rendering in a canvas on a Swing window. There is even a tutorial on doing it in the tutorials section of the website.
You can also do it using a fully rendered window and then putting the buttons inside the scene. I'm surprised LWJGL doesn't support this though as jME3 is built on top of LWJGL.
Give that I have written a JPanel with many different components on it, is there a way to apply an overall "dilate" ability on the panel so that everything in it stretches proportionally when I resize my window?
That is, if I manually resize my window to be 1/4 the size, everything in the panel should also shrink by 1/4 so the new panel is just a dilation of the first. Given that I have not designed the individual components inside to do this (there are many) is there any easy way to make the panel behave this way?
UPDATE: In order to be more clear on the solution I need, I will describe the panel contents:
The panel is a "game" of sorts, with a single null-layout and dozens of ImageIcons flying around the screen at any time. The ImageIcons are preloaded PNG files, which already have a permanent size. Of course, I could manually resize each ImageIcon and reposition them relative to window size, but that would involve recoding many components.
There are no buttons or text to worry about, so what I'm really looking for is some kind of "postprocessed" resize where the panel simply shrinks whatever's rendered by some porportion (think of resizing an image in Photoshop).
One option is of course to give up swing all together and use some 3rd party widget component library which draws itself using any Graphics. Then you can either draw the widgets on the image and resize the image, or, better yet, apply a transform to the graphics object you pass to the library.
If you do want to stick with swing there is the SwingUtilities.paintComponent method, which you could use to paint the Panel onto a BufferedImage which you could then resize. (I've used this myself to do some nice transitions between "views" in a game.)
The problem is of course that you somehow need to translate the user input accordingly. I have no solution for this right now, but the above perhaps helps you in some way.
You can try to override paintChildren() method of the panel and scale graphics to achieve desired visible size.
You could try J(X)Layer, see http://www.pbjar.org/blogs/jxlayer/jxlayer40/
Using layout managers instead of absolute positioning of the widgets will give you this behaviour. See the oracle tutorials: Using Layout Managers.
Do you really want fonts to resize on resize events? I don't know a layout manager which will do that for you.
I have an application that displays plots using JFreeChart. As it happens, these plots are big and JFreeChart is not terribly fast, resulting in atrocious redraw times, particularly when resizing the plot.
What I am after is a way to stretch an image representing the plot while resizing (a bit like the iPhone will present a screenshot of a stopped application while it gets started again), and perform a full redraw only after the user has released the mouse (i.e. once the final size of the plot is known).
The interaction features of the chart sould stay intact (when not resizing, obviously).
Is there a generic solution / Swing wrapper for this? (there is no reason why it should be JFreeChart-specific).
Cheers
No concrete answer, just a possible strategy
on starting the resize, paint the plot into a BufferedImage and show and resize that image instead of the plot
on stopping resize remove the image and show the plot again
in JDK 7, you can use a JLayer for the image/manipulation.
Edit
Alternatively (for JLayer), you could use a CardLayout: showing one card with the image while resizing and the another card with the plot while not resizing. SwingX ImagePainter can do the image scaling during the resize