JavaFX play local video with whitespace in a path - javafx-2

I'm building a small application, that can play video, the problem, that when I add a video with a whitespace in it's path - it gives me an error:
java.net.URISyntaxException: Illegal character in opaque part at index 13: FILE:C:/Video menu/video/03.mp4
Here's my scene:
Group root = new Group();
Scene scene = new Scene(root, 1280, 1024, Color.BLACK);
String path = new String("FILE:C:/Video menu/touchMV/03.mp4");
URI uri = new URI(path);
root.getChildren().add(
MediaViewBuilder.create()
.mediaPlayer(
MediaPlayerBuilder.create()
.media(
new Media(
path
)
).build()
).build()
);
stage.setScene(scene);
stage.show();
The Media(java.lang.String source) docs said that it have Constraints:
The supplied URI must conform to RFC-2396 as required by java.net.URI.
Only HTTP, FILE, and JAR URIs are supported.
I tried to pass a Media() constructor an (new URI(path)).toString(); and (new URI(path)).toASCIIString() it didn't worked. Changing a whitespace to %20 didn't worked as well.
What can I do in this situation?

I don't know the cause of your problem, but it works if you create a File first and call File#toURI#toASCIIString.
File file = new File("C:\\Video menu\\touchMV\\03.mp4");
String path = file.toURI().toASCIIString();

Related

Accessing Local Resource (local directory- outside project) in Vaadin 14/RapidclipseX IMG component

How to access the local image file from my hard drive (outside project folder) in the image component (to make an image gallery)? How to write the path of the file? in Vaadin 14/RapidclipseX.
It only takes either path from the project or URL. In my project users have to upload the images and I want to make a gallery that will show the images.
I tried all the below way but didn't work:
D:\\Canavans\\Reports\\256456\\424599_320943657950832_475095338_n.jpg
D:\Canavans\Reports\256456\424599_320943657950832_475095338_n.jpg
code (Tried this way as well):
for(final File file: files)
{
System.out.println(file.getName());
this.log.info(file.getName());
this.log.info(file.getAbsolutePath());
final String path = "file:\\\\" + file.getAbsolutePath().replace("\\", "\\\\");
this.log.info(path);
final Image img = new Image();
img.setWidth("300px");
img.setHeight("300px");
img.setSrc("file:\\\\D:\\\\Canavans\\\\Reports\\\\256456\\\\IMG20171002142508.jpg");
this.flexLayout.add(img);
}
Please Help! Thanks in advance. Or is there any other way to create an image gallery?
Hmm as far as I know if you want to access resources outside the resource folder you can create a StreamResource and initialize the image with that. If you want to use the images "src" property then the file has to be inside one of Vaadin's resource folders (for example the 'webapp' folder).
Here is a simple example on how to create the image with a StreamResource:
final StreamResource imageResource = new StreamResource("MyResourceName", () -> {
try
{
return new FileInputStream(new File("C:\\Users\\Test\\Desktop\\test.png"));
}
catch(final FileNotFoundException e)
{
e.printStackTrace();
return null;
}
});
this.add(new Image(imageResource, "Couldn't load image :("));
Hope this helps :)

cucumber hook scenario.embed always create screenshot at project root

In cucumber hook scenario.embed always create screenshot at my project root directory. I need it to create it different location
scenario.embed(screenshot, "image/png");
I create below code still no wayout:
File screenShot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// extracting date for folder name.
SimpleDateFormat dateFormatForFoldername = new SimpleDateFormat("yyyy-MM-dd");//dd/MM/yyyy
Date currentDate = new Date();
String folderDateFormat = dateFormatForFoldername.format(currentDate);
// extracting date and time for snapshot file
SimpleDateFormat dateFormatForFileName = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");//dd/MM/yyyy
String fileDateFormet = dateFormatForFileName.format(currentDate);
String filefolder="./ScreenShots"+"/FailCase/"+folderDateFormat+"/";
// Creating folders and files
File screenshot = new File(filefolder+fileDateFormet+".jpeg");
FileUtils.copyFile(screenShot, new File(screenshot.getPath()));
byte[] fileContent = Files.readAllBytes(screenshot.toPath());
scenario.embed(fileContent, "image/png");
How to pass a directory path to embed funtion or override it?
#mpkorstanje - he is rightly pointed about it
As per his comment:
Use OutputType.BYTES and send the bytes directly to scenario.embed and write them directly to the screenshot file
But my issue was I am using mkolisnyk package and when I am using #AfterSuite annotation of it, it creating fail file images over root folder. seems bug in mkolisnyk package.
Mixing AfterSuite of testng and #ExtendedCucumberOptions of mkolisnyk works for me

Select and manipulate particular paths within a path group fabric.js

I am making an app that involves shapes like cylinders and boxes, and need to be able to do this with fabric.js. I know about three.js but for my purposes, it must be in 2D.
Initially I thought I would just create them in 3D software and render images which can then be added to the canvas, which I did successfully...
However, I have run into a hurdle where fabric only allows patterns to be filled onto paths or objects (rect, circle etc.)....not images (png).
Since I absolutely need patterns, I now need to create these cylinders in SVG. I have gotten as far as making the cylinders in Illustrator, saving them as SVG's and then using them on the canvas, then adding fill patterns on them. So far so good.
Now I want to be able to fill a different pattern for the top of the cylinder, and a different pattern to the side BUT still have it as one object.
So...How can I select and manipulate particular paths within a path group? Is there anyway to give each path within the group a custom attribute (eg. name) which I can then target? Do I need to create two seperate SVG files and then add them seperately, and if so, how can I do this and still have it as one object?
Here's how I am adding the svg to the canvas...
fabric.loadSVGFromURL("/shapes/50-250R.png", function(objects) {
var oImg = fabric.util.groupSVGElements(objects);
oImg.perPixelTargetFind = true;
oImg.targetFindTolerance = 4;
oImg.componentType = "Shape";
oImg.lockUniScaling = true;
oImg.lockScalingX = true;
oImg.lockScalingY = true;
oImg.setControlsVisibility({'tl': false, 'tr': false, 'bl': false, 'br': false});
canvas.add(oImg);
canvas.renderAll();
});
Here is how I am adding the pattern...
var textureIMG = new Image;
textureIMG.crossOrigin = "anonymous";
textureIMG.src = texture.image;
obj.setFill(); //For some reason, the fill doesn't happen without this line.
var pattern = new fabric.Pattern({
source: textureIMG,
repeat: 'repeat'
});
if (obj instanceof fabric.PathGroup) {
obj.getObjects().forEach(function(o) {
o.setFill(pattern);
});
} else {
obj.setFill(pattern);
}
canvas.renderAll();
Thanks in advance.
So I managed to figure this out. Each path within the path group is stored in the 'paths' array of the object.
I can now add a pattern to the top of the cylinder using...
var obj = canvas.getActiveObject();
obj.paths[0].fill = patternOne;
and to the sides using...
obj.paths[1].fill = patternTwo;

WinXP Only Bitmap.Save ArgumentException Parameter Not Valid

Basically the code is trying to take a source image, draw some custom text on it and save the new image to the file system.
When I run the code in Windows 7, it runs fine, but when I run it in WinXP it creates an exception in the imgCopy.Save line anytime after the first DrawString.
The exception is ArgumentException (parameter is not valid). It's like the DrawString corrupts the image under WinXP...?
The build is for the x86/.NET 4.0 runtime. Any ideas why the exception under XP?
// imgSrc is actually passed into the method with the rec object
// this is just for repro
using (var imgSrc = new System.Drawing.Bitmap(rec.SrcFile))
using (var imgCopy = imgSrc.Clone() as Bitmap)
using (var gImg = Graphics.FromImage(imgCopy)) //shorten var names for this post
{
imgCopy.Save(rec.DstFile, ImageFormat.Jpeg); //Happy here
gImg.SmoothingMode = SmoothingMode.AntiAlias;
imgCopy.Save(rec.DstFile, ImageFormat.Jpeg); //Also no problem
gImg.DrawString(rec.Name, fntArial16, Brushes.Black, new Rectangle(170, 105, 650, 50), sfCenter);
imgCopy.Save(rec.DstFile, ImageFormat.Jpeg); //<-- Fails here
}
Edit: Code for the parameters:
private static Font fntArial16 = new Font("Arial", 16, FontStyle.Bold);
private static StringFormat _sfCenter;
private static StringFormat sfCenter {
get {
if (_sfCenter == null) {
_sfCenter = new StringFormat();
sfCenter.Alignment = StringAlignment.Center;
sfCenter.LineAlignment = StringAlignment.Center;
}
return _sfCenter;
}
}
We narrowed the problem down to the .jpg file containing XMP (Extensible Metadata Platform) data. Once we removed that from the file it worked on WinXP correctly. Unfortunately the tool that generated the file didn't have the option to exclude this, so we went with the .png file instead and that works fine as well.

How to set up Velocity to find templates in the file system on Windows?

I have a very simple Velocity application that works on Linux and MacOS and fails on Windows. The problem is with the resource locations. I just give it "/" to allow it to recognize file system paths, but on Windows that fails to work for "c:/....." pathnames. I suspect that there is a simpler solution to this, but what?
velocityEngine = new VelocityEngine();
// we want to use absolute paths.
velocityEngine.setProperty("file.resource.loader.path", "/");
try {
velocityEngine.init();
} catch (Exception e) {
throw new MojoExecutionException("Unable to initialize velocity", e);
}
I put velocity templates in the classpath and read them in with Class.getResourceAsStream.
It should go something like this:
// stuff.velocity is a file that lives directly under WEB-INF/classes
// that contains the velocity template
InputStream inputStream = Class.getResourceAsStream("/stuff.velocity");
String template = readTemplateFromFile(inputStream);
VelocityContext context = new VelocityContext( );
// insert any parameters into context now
Writer writer = new StringWriter();
Velocity.evaluate( context, writer, "LOG", template );
and now writer should hold the result of applying the parameters to the template.
Will Glass' comment below looks like a good thing to check out. When I was using velocity it was to generate notification emails, there were not a lot of them and I had the work farmed out to a separate thread so performance was not a big deal at the time.

Resources