I've many video files. All the types are different (mkv, avi, mp4, flv, etc.).
I want to iterate these files and get the duration of the movies.
Currently I use vlcj which is OK, but the code is a little bit confusing me.
I have to play the media before I can get the length. Then stop the media. This is weird, isn't it.
Can I do that better somehow? I've heard about xuggler, but the development has stopped.
I need an API or 3rdparty component that is still alive. And I don't want to play the media before I play :)
Finally, I've solved the problem with Xuggle.
After setup I had to add these lines, and it works fine:
IContainer container = IContainer.make();
if (container.open(movie, IContainer.Type.READ, null) < 0) {
throw new RuntimeException("Cannot open '" + movie + "'");
}
logger.info("# Duration (ms): " + ((container.getDuration() == Global.NO_PTS) ? "unknown" : "" + container.getDuration() / 100));
logger.info("# File size (bytes): " + container.getFileSize());
logger.info("# Bit rate: " + container.getBitRate());
BTW, the setup was awful, but finally... got this code to work.
See Java Media Framework.
http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/index.html
Here you will find links to other similar projects also http://en.wikipedia.org/wiki/Java_Media_Framework
Related
I write discord bot with using JDA and i have one important question how to download attachments or work with them? Because my IntelliJ say "Deprecated API usage" for method like attachment.downloadToFile("name.png);
So now we shouldn't download users files send in message? Or how we should do it in good way? I search a lot of wiki from JDA and different posts, but everywhere i didn't see, a new option to handle this download files, becasue all methods to download, are "Deprecated API" even method like "attachment.retrieveInputStream().join()" retrieveInputStream its too not good way :(
Search a lot on wiki/others pages for more information but nothing found :(
The deprecation notice says this:
Deprecated.
Replaced by getProxy(), see FileProxy.downloadToFile(File)
This means you should use attachment.getProxy().downloadToFile(File) instead.
Example:
attachment.getProxy().downloadToFile(new File("myimage.png")).thenAccept(file -> {
System.out.println("Written to file " + file.getAbsolutePath() + ".");
});
Or using NIO instead:
attachment.getProxy().downloadToPath().thenAccept(path -> {
System.out.println("Written to file " + path + ". Total size: " + Files.size(path));
});
My team has created a CMS. When it's API is called by the client (using POST - with parameters), it responds with raw HTML, which is then injected into the client's page.
I am assigned to create automated testing specifically for the HTML (not the client page). On my computer I can save the HTML in a file and open with a browser to test it out locally.
To get the test to run on a build server or through Sauce Labs, I am trying to figure out a way to render the HTML so I can have my test framework grab a screenshot to be compared. My test framework is Java/Junit using Selenium bindings, and I use Applitools for screenshot comparison.
I looked into PhantomJS but got a bit lost in the JS world (I am much more comfortable with Java). Also it appears that these artifacts are quite dated in Maven. If this is suggested, I would really appreciate an example.
I have found topics related to posting to the http endpoint using the Junit approach (leveraging Rest Assured), but I am stuck on what to do with the HTML response and how to plug that into a Selenium test. Please, can anyone offer guidance or suggest a tool to do this?
You could use the data scheme to load the html:
driver.get("data:text/html;charset=utf-8," + URLEncoder.encode(pageHtml, "UTF-8"));
Though you may be limited by the length and it won't load the resources present in a separate folder.
Another way would be to execute the requests directly in the page and to then rewrite the whole page with the result.
Something like:
// set domain
driver.get("https://stackoverflow.com");
// navigate some HTML from a request
navigate(driver, "POST", "/search", "q=abcd");
public void navigate(driver, method, path, body) {
String JS_NAVIGATE_REQUEST =
"(function(method, path, body, callback){ " +
" var xhr = new XMLHttpRequest(); " +
" xhr.open(method, path, true); " +
" xhr.onloadend = function(){ " +
" document.write(xhr.responseText); " +
" document.close(); " +
" callback(); " +
" }; " +
" document.write(''); " +
" xhr.send(body); " +
"}).apply(window, arguments); " ;
((JavascriptExecutor)driver).executeAsyncScript(JS_NAVIGATE_REQUEST, method, path, body);
}
I would save the HTML into a file and use IE to display that file.
You can use badboy tool to capture the screenshots of the HTML files saved locally but this is not including selenium integration. It is just to have the baseline screenshots from the HTML saved locally.
Save all the responses in HTML with some predefined naming convention like SS_1,SS_2.
Open badboy and pass the path of 1 file in the browsing pane (at upper right) or use "Request" from tools (Drag & Drop) and provide the path of first file saved locally.
Put snapshot tool below it and configure to save snapshots.
Add variables ${iterator} and provide values
Double click on "Request" and change the file name suffix from SS_1 to ${iterator}
Now, configure step to run for each value of variables by double clicking on the step and selecting the second radio button (For each value of variable) .
Reference tool - Badboy
I am writing a Dropbox console application. I need to find last modification for my account. I can get file metadata with date of last modification, like this:
DbxEntry.WithChildren listing = client.getMetadataWithChildren(path);
for (DbxEntry child : listing.children) {
System.out.println(" " + child.name + ": " + child.toString());
}
But how can I find the latest modification for all of my folders?
The Dropbox API and the official Dropbox Java SDK don't expose a modified time for folders, but we'll consider it a feature request.
For files, you can access clientModified and serverModified on FileMetadata.
(Note that the code in your question uses the old, deprecated Java SDK, so you should switch to the new one.)
The tutorial http://download.oracle.com/javase/tutorial/sound/capturing.html
does not cover how to select microphone.
I am enumerating mixers with the following code
System.out.println("Searching for microphones");
for(Mixer.Info mixerinfo : AudioSystem.getMixerInfo()) {
mixer = AudioSystem.getMixer(mixerinfo);
//System.out.println(mixerinfo.toString());
if( mixer.isLineSupported(Port.Info.MICROPHONE) ) {
mixers.add(mixer);
System.out.println(Integer.toString(mixers.size()) + ": " + mixerinfo.toString());
}
}
i.e. by presense of microphone input. But next, having a mixer, I can't get line to read.
If I use mixer.getTargetLineInfo(), I receive an array of one Info, which when passing to mixer.getLine returns an object of type com.sun.media.sound.PortMixer$PortMixerPort, which is not ducumented.
If I use mixer.getTargetLines() I get an empty array.
If I create my own DataLine.Info and pass it to the mixer's getLine, I get unsupported exception.
So, what to do?
Left-field suggestion.
Provide a visual rendering of each sound line, in a component along the lines of the AudioPlotPanel or a simpler RMS volume. It should not take the user too long to figure which sound line they are yodeling through. ;)
I'm trying to do the same thing. I haven't quite found a good solution yet but I can tell you that's not working out because you're trying to get a DataLine from a Port mixer. If and when I figure it out I'll be sure to let you know.
How can I "eject" a volume with Java, cross platform?
I have a program that does some operations on a removable drive (USB memory card reader), and once it's done, I want the program to eject/unmount/remove (depending which os lingo we're talking in) the memory card.
Is there a reliable cross-platform method of doing this?
Probably isn't the answer you're looking for, but...
No.
To my knowledge, there isn't an established single-platform way of doing this. For that matter, I've never come across a Java way of doing this. A rather scary C# CodeProject does allow ejecting devices, but only on Windows.
The various, depressingly poor, Java USB libraries don't even hint at ejecting devices. They don't work across all platforms, so even if they did it wouldn't help you.
My suggestion: gin up some scripts or executables for each platform, and then just spin up a Process as needed.
A litle late response but i thought it was worth sharing...
Since the default Java API does not come with this feature on it, you could use external libraries as mentioned above, however i personally found it much more convenient (for windows) to have a third party exe file in the jar's classpath, extract it in the temp folder, execute it when needed and then remove it once the aplication is done with it.
As a third party program i used this which is a CLI only program that can do a few tricks with connected devices, and then used this code:
FileUtils.copyInputStreamToFile(MyClass.class.getClassLoader().getResourceAsStream(program),TEMP_EJECT_PROGRAM);
to export it to the temp file location (Using ApacheIO, you can definately do without it), and this code:
private void safelyRemoveDrive(final String driveLetter) {
new Thread(new Runnable() {
public void run() {
if (TEMP_EJECT_PROGRAM.exists()) {
System.out.println("Removing " + driveLetter);
try {
Process p = Runtime.getRuntime()
.exec("\"" + TEMP_EJECT_PROGRAM.toString() + "\" " + driveLetter + " -L");
p.waitFor();
Scanner s = new Scanner(p.getInputStream());
while (s.hasNextLine())
System.out.println(s.nextLine());
s.close();
System.out.println("Removed " + driveLetter + ".");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
to remove the drive. The pieces of code above are definately not suited for all aplications and the second one in perticular is not the greatest, there are other much better ways to do it than spawning an anonymus thread... Still however you get the idea behind it :)
Lastly, I sugest you inform the user appropriately and ask for their concent before executing any third-party software in their machine...
I hope this was helpful :-)