Can I play video using Vaadin framewotk ?
The main idea is loading video files from local drive in flv or avi formats and play it in web using vaadin framework.
Thanks.
There is a sample in the Sampler: http://demo.vaadin.com/sampler/#FlashEmbed
You can see the source by clicking 'view source', and it will show you something like this:
Embedded e = new Embedded(null, new ExternalResource(
"http://www.youtube.com/v/meXvxkn1Y_8&hl=en_US&fs=1&"));
e.setMimeType("application/x-shockwave-flash");
e.setParameter("allowFullScreen", "true");
e.setWidth("320px");
e.setHeight("265px");
addComponent(e);
Obviously, you'll want to change the ExternalResource to something else (e.g FileResource, ClassResource, StreamResource, ...) in order to play local files.
Vaadin version 6.7 brought a new class Video that uses the new HTML5 "video" element to embed video on a page.
My posting on the Vaadin Forum provides the source code for an example app.
The main part of that code, when populating a window or layout:
Video v = new Video( "video" ); // Instantiate video player widget.
// Specify a list of your video in one or more formats.
// Different browsers support various different video formats.
v.setSources(
new ExternalResource( "http://www.example.com/media/example_video.mp4" ),
new ExternalResource( "http://www.example.com/media/example_video.ogv" )
);
v.setWidth( "640px" ); // Set size of the video player's display area on-screen.
v.setHeight( "360px" );
this.addComponent( v ); // Add the component to the window or layout.
Oops, I just re-read you posting -- you want to play local video files. Do you mean local to the user's computer or the Vaadin app server-side computer? Either way, you may be able to manipulate the "ExternalResource" seen above, or another subclass of Vaadin Resource to access a local file.
You can use the Embedded Class to embed videos.
NOTE: This is for local files:
FileResource fileResource = new FileResource(new File("/Users/user/Downloads/DBTI_1991_teaser_HD.mp4"));
Video vd = new Video();
vd.setAutoplay(true);
vd.setSource(fileResource);
this.addComponent(vd);
Another alternative is the Vaadin add-on "YouTubePlayer" if you want to access a video specifically from YouTube.com.
Related
I am trying to get VLCJ to do a visualizer for the mp3 files its playing from a HTTP stream. Video shows up when I stream one. But when audio plays, nothing happens.
This is my code on the cliente side
EmbeddedMediaPlayerComponent empc = new EmbeddedMediaPlayerComponent();
String[] op = {"audio-visual=visual", "effect-list=spectrum", "effect-width=800", "effect-height=80"};
empc.mediaPlayer().media().play("http://127.0.0.1:" + port, op);
There's a lot more code, but nothing directly related to VLCJ.
I can post the server code if you think it's necessary, but I think it's not needed since the media reaches the client perfectly.
So, audio and video work fine, but the visualizer simply doesn't show up.
Any help would be appreciated.
First, check if you have the visualisation plugins installed on your OS distribution.
I am using Linux Mint and those plugins are NOT installed by default when you install VLC.
Do this:
sudo apt install vlc-plugin-visualization
Second, it seems you have to set the visualisation options on the MediaPlayerFactory rather than passing them when you invoke play() on the media player.
For example:
String[] options = new String[] {"--audio-visual=visual", "--effect-list=scope,vuMeter,spectrometer,spectrum"};
factory = new MediaPlayerFactory(options);
mediaPlayer = factory.mediaPlayers().newEmbeddedMediaPlayer();
This example configures the factory before creating a media player from it, you can use any of the media player factory creation methods.
The visualisations scale with the size of the window, I could not get the width and height parameters to do anything.
This is fine for audio.
If you play video, then the video will go the video surface embedded in your application and VLC will open up a new separate window to show the visualisations (probably you don't want that).
I'm using the Java botbuilder to build a microsoft teams bot. I want to add Cards to my bot (e.g. to embed links, quick replies, and images).
In the above link it says: suggested actions are not supported in Microsoft Teams: if you want buttons to appear on a Teams bot message, use a card.
However, I can find no documentation on how to add a 'card' to the Activity schema.
I tried:
1. Using suggested actions
I tried adding my List<CardAction> to the SuggestedActions
field in Activity but they were not rendered by microsoft teams
(as expected, the documentation says this is not supported).
2. Using Attachments
I suspect it could be done using attachments, but can only find
documentation for the C#/JS versions (e.g.
https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-rich-cards?view=azure-bot-service-3.0).
So I want to know how to add 'a card' to Activity schema so it can be rendered by my bot.
The BotFramework Java SDK is still in preview, so there isn't a lot of documentation I can point you towards. However, here is an example of adding a HeroCard to a reply.
Activity reply = new Activity()
.withType(ActivityTypes.MESSAGE)
.withRecipient(activity.from())
.withFrom(activity.recipient())
.withAttachments(Arrays.asList(
new Attachment()
.withContentType("application/vnd.microsoft.card.hero")
.withContent(new HeroCard()
.withTitle("Hero Card")
.withSubtitle("BotFramework")
.withButtons(Arrays.asList(new CardAction()
.withValue("https://learn.microsoft.com/en-us/azure/bot-service/")
.withTitle("Get started")
.withType(ActionTypes.OPEN_URL)
))
.withImages(Collections.singletonList(new CardImage()
.withUrl("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg"))))
));
You can also take a look at the SDK Attachment Tests for more examples.
Hope this helps!
I have an application developed using struts2. One of my web page has a div in which it displays a world map created using Google map API. On click of a button I want to save this map as an image on the server location. I tried this using the ROBOT class but this is not working. My application supports IE8. Below is the code I wrote:
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rect = new Rectangle(screenDim);
Robot rob = new Robot();
BufferedImage img = rob.createScreenCapture(rect);
String FileName="D:\\SP_Maps\\Map.png";
ImageIO.write(img, "png", new File(FileName));
Basically I tried to take a screen shot of the page on click of a button and save it as an image. This works fine on my local host but, when I deploy this on my server and try to get the screen shot I just get a black page saved as png image.
While you are developing a web application you may use javascript if you are interested..
To get a screen shot and save it with any format you may use PhantomJS
PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast
and native support for various web standards: DOM handling, CSS selector,
JSON, Canvas, and SVG.
Check those examples written with PhantomJS:
https://github.com/ariya/phantomjs/wiki/Examples
Also check this tutorial Taking website screenshots using PhantomJS
The tutorial is about taking a web shot and saving it as JPEG, PNG, PDF ... etc
Hope this helps you...
Can you explain your use case clearly ? If I understand correctly you have a web application which has a functionality to take a screen capture upon user action? Ideally, Java Robot utility should use to do automated testing of java applications. As per the doc
The primary purpose of Robot is to facilitate automated testing of
Java platform implementations.
Maybe you can try using phantomjs.
example
var page = require('webpage').create();
page.open('http://google.com', function () {
page.render('google.png');
phantom.exit();
});
https://github.com/ariya/phantomjs/wiki/Quick-Start
To perform user actions like button clicks, you can use casper.js
http://casperjs.org/quickstart.html
I am trying to render and export FusionCharts completely on the server. I am aware of solutions such as FCimg and FusionCharts .NET Solution. I have also implemented a Java solution that uses the Process class to run wkhtmltoimage.
However, I am trying to find a pure Java solution of doing this. I have an html file that includes FusionCharts JS Libraries and code to generate the fusion chart. I found JxBrowser that properly renders the chart but it requires X-Server for it to work on Linux. I also have tried Cobra/Lobo Browser but it does not fully support JavaScript. Are there any other ways to render and export fusion charts on the server or atleast render an html file that includes JavaScript completely in Java (and that does not require xserver)?
Thanks in advance for all the help!
Update: Solution that does not require xserver: WebRenderer. The Swing Edition is the only edition that supports HTML5 as of July 9th, 2012. You can use the swing edition to capture the image without a GUI.
I found a way that uses Eclipse's SWT Browser. However this cannot be run in an headless mode. You will have to use xserver to implement this. See this question.
Since this requires xserver and cannot be run in an headless mode, I would suggest using JxBrowser. It is a lot simpler and all you need is to generate an html file with all the fusion charts scripts. See #1, #2, #3
You have to create a template.html file that contains the header
(<html><head>), jquery.min.js, FusionCharts.js,
FusionCharts.HC.js, FusionCharts.HC.Charts.js. Make sure each of
these scripts are in their own script tags (<script type="text/javascript"> [js code] </script>)
Now add another JavaScript function with its own script tags containing the steps to render the chart. For example:
function load() { FusionCharts.setCurrentRenderer('javascript'); var chart = new FusionCharts("swf", 'chart0', "width", "height", "0", "1"); chart.setXMLData("XML DATA HERE"); chart.render("divNAMEHere"); }
Now you need to call the load() function onload, create a div to render the chart in, and end the html file. For example:
`
test
`
Create a new class that imports the eclipse swt browser libraries. Instantiate Display, Shell, and Browser (use this as a guideline to help understand what is happening: http://www.roseindia.net/tutorials/swt/swt-browser.shtml).
Set the text of the browser (browser.setText("htmlcode")) to the html code from template.html. The best way to do this would be to read the file using BufferedReader.
Lastly, the image takes some time to render. Now there is probably a better way to do this but if you want to just get it working, I set up a count and it captures the image after a certain number. This is what you need to add to the end:
int i = 0;
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
i++;
// System.out.println(i);
if(i==100)
{
GC source = new GC (shell);
Image image = new Image(display, browser.getClientArea());
source.copyArea(image, 0, 0);
ImageLoader io = new ImageLoader ();
io.data = new ImageData[] { image.getImageData() };
File f = new File (currentDir+"/workpng.png");
io.save (f.getAbsolutePath(), SWT.IMAGE_PNG);
}
}
}
I would like to put a flash game i made with CS.5 (it was exported to a .swf) into a java application. From research i found some ways to to it might be using a embedded web browser or some kind of a flash player:
Embed .swf file to my Jframe
Embed a web browser within a java application
But is this the best way to do it and will it keep the interactivity (ie. the game). It will also fit exactly so if a embedded web browser showed back/front/url/etc. buttons then i can't use it
So whats the best way to do this? And will a flash player inside the java application keep the interactivity (the game working the same as it would in a web browser or in the flash player application)?
You can used the swf COM API ExternalInterface.call() to communicate with the swf applcaition.
But it only support action script 3 and later.
public void callFunction( String function, String params )
{
if ( !created )
return;
String request = "<invoke name=\""
+ function
+ "\"><arguments><string>"
+ params
+ "</string></arguments></invoke>";
Variant[] args = new Variant[1];
args[0] = new Variant( request );
flashObject.invokeNoReply( DISPID_CALLFUNCTION, args );
}
This is a swt swf call function implements.
You can implement a swf container, it's very easy. Some JNI jars such as JNative, JNA can help you.
I implement a win32 library swt-win32-extension.jar, it contains a custom swf container, but it can't be used by swing.