Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
albertattard committed Mar 6, 2015
1 parent 0b86f29 commit e674f3d
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.javacreed.examples.io;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.UserDefinedFileAttributeView;

public class Example {

public static void main(final String[] args) throws Exception {
final Path file = new File(Example.class.getResource("/samples/example.txt").toURI()).getAbsoluteFile().toPath();
final Path file = Paths.get(Example.class.getResource("/samples/example.txt").toURI()).toAbsolutePath();

final UserDefinedFileAttributeView view = Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);

Expand Down
9 changes: 9 additions & 0 deletions io/How to Read File Attributes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>uk.co.caprica</groupId>
<artifactId>vlcj</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.javacreed.examples.io;

import java.util.concurrent.TimeUnit;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import com.sun.jna.NativeLibrary;

public class Example {

public static void main(final String[] args) throws Exception {

final String vlcLibPath = "C:\\Users\\Mona Lisa\\Downloads\\vlc-2.1.5";
final String mediaPath = "\\\\192.168.75.25\\Data\\sd\\videos\\England\\2014_2015\\Premier_League\\Arsenal_vs._Aston_Villa\\908093_0\\Arsenal_vs._Aston_Villa.mp4";

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcLibPath);
final EmbeddedMediaPlayerComponent embeddedMediaPlayerComponent = new EmbeddedMediaPlayerComponent();
EmbeddedMediaPlayer embeddedMediaPlayer = embeddedMediaPlayerComponent.getMediaPlayer();
embeddedMediaPlayer.prepareMedia(mediaPath);
embeddedMediaPlayer.parseMedia();

System.out.println("Length: " + embeddedMediaPlayer.getLength());
System.out.println("Dimentions: " + embeddedMediaPlayer.getVideoDimension());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.javacreed.examples.io;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import com.sun.jna.NativeLibrary;

public class Example2 {

public static void main(final String[] args) throws Exception {

final String vlcLibPath = "C:\\Users\\Mona Lisa\\Downloads\\vlc-2.1.5";
final String mediaPath = "\\\\192.168.75.25\\Data\\sd\\videos\\England\\2014_2015\\Premier_League\\Arsenal_vs._Aston_Villa\\908093_0\\Arsenal_vs._Aston_Villa.mp4";

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcLibPath);

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final JFrame frame = new JFrame("Playing Video with VLC (Part 1)");
final EmbeddedMediaPlayerComponent embeddedMediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame.setContentPane(embeddedMediaPlayerComponent);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200, 800);
frame.setVisible(true);

final EmbeddedMediaPlayer mediaPlayer = embeddedMediaPlayerComponent.getMediaPlayer();
mediaPlayer.playMedia(mediaPath);

System.out.println("Length: " + mediaPlayer.getLength());
System.out.println("Dimentions: " + mediaPlayer.getVideoDimension());

frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
mediaPlayer.release();
} catch (Exception ex) {/* Ignore */}
}
});
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.javacreed.examples.io;


public class Example3 {


public static void main(String[] args) throws Exception {



System.load("C:\\Windows\\System32\\Shell32.dll");


System.out.println("Done");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.javacreed.examples.io;

import java.awt.Dimension;
import java.awt.Frame;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
import uk.co.caprica.vlcj.player.MediaPlayerEventListener;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import com.sun.jna.NativeLibrary;

public class Example4 {

public static void main(final String[] args) throws Exception {

final String vlcLibPath = "C:\\Users\\Mona Lisa\\Downloads\\vlc-2.1.5";
// final String mediaPath = "\\\\192.168.75.25\\Data\\sd\\videos\\England\\2014_2015\\Premier_League\\Arsenal_vs._Aston_Villa\\908093_0\\Arsenal_vs._Aston_Villa.mp4";
final String mediaPath = "\\\\192.168.75.25\\Data\\sd\\videos\\Argentina\\2014\\Primera_A\\Arsenal_de_Sarandí_vs._Banfield\\937560_0\\Arsenal_de_Sarandí_vs._Banfield.mp4";
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcLibPath);

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final EmbeddedMediaPlayerComponent embeddedMediaPlayerComponent = new EmbeddedMediaPlayerComponent();

final JFrame application = new JFrame("Test");
application.setContentPane(embeddedMediaPlayerComponent);
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setExtendedState(Frame.MAXIMIZED_BOTH);
application.setVisible(true);

final EmbeddedMediaPlayer embeddedMediaPlayer = embeddedMediaPlayerComponent.getMediaPlayer();
embeddedMediaPlayer.playMedia(mediaPath);

final MediaPlayerEventListener listener = new MediaPlayerEventAdapter() {
@Override
public void positionChanged(final MediaPlayer mediaPlayer, final float newPosition) {
final Dimension dimension = mediaPlayer.getVideoDimension();
if (dimension != null) {
System.out.printf("%d X %d%n", dimension.width, dimension.height);
embeddedMediaPlayer.removeMediaPlayerEventListener(this);
application.setVisible(false);
application.dispose();
}
}
};

embeddedMediaPlayer.addMediaPlayerEventListener(listener);
}
});

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package com.javacreed.examples.io;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

public class Example5 {

private static class MediaInfo {

public static MediaInfo parse(final String data) {

final MediaInfo mediaInfo = new MediaInfo();

Section section = null;

for (final String line : data.split("(\\r\\n|\\r|\\n)")) {
if (line.isEmpty()) {
section = null;
continue;
}

if (section == null) {
section = mediaInfo.addSection(Section.parse(line));
continue;
}

section.add(NameValue.parse(line));
}

return mediaInfo;
}

private final Map<String, Section> sections = new LinkedHashMap<>();

public Section addSection(final Section section) {
final String name = section.getName();
if (sections.containsKey(name)) {
throw new IllegalArgumentException("Duplicate section name: '" + name + "'");
}

sections.put(name, section);
return section;
}

@Override
public String toString() {
final StringBuilder formatted = new StringBuilder();
if (sections.isEmpty()) {
formatted.append("No information found!!!");
} else {
for (final Section section : sections.values()) {
formatted.append(section);
}
}

return formatted.toString();
}
}

public static class NameValue {
public static NameValue parse(final String line) {
final String[] parts = line.split(":", 2);
return new NameValue(parts[0].trim(), parts[1].trim());
}

private final String name;
private final String value;

public NameValue(final String name, final String value) {
this.name = Objects.requireNonNull(name);
this.value = Objects.requireNonNull(value);
}

public String getName() {
return name;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return String.format("[%s] = '%s'", name, value);
}

}

private static class Section {
public static Section parse(final String line) {
if (line.contains(":")) {
throw new IllegalArgumentException("Section name should not have ':'");
}

return new Section(line.trim());
}

private final String name;

private final Map<String, NameValue> values = new LinkedHashMap<>();

public Section(final String name) {
this.name = Objects.requireNonNull(name);
}

public void add(final NameValue nameValue) {
final String name = nameValue.getName();
if (values.containsKey(name)) {
throw new IllegalArgumentException("Duplicate name: '" + name + "'");
}

values.put(name, nameValue);
}

public String getName() {
return name;
}

@Override
public String toString() {
final StringBuilder formatted = new StringBuilder();
formatted.append(name).append("\n");
if (values.isEmpty()) {
formatted.append(" No values!!!\n");
} else {
for (final NameValue nameValue : values.values()) {
formatted.append(" ").append(nameValue).append("\n");
}
}
return formatted.toString();
}
}

private static String executeMediaInfo(final String mediaPath) throws IOException, InterruptedException {
final String exePath = "C:\\Users\\Mona Lisa\\Downloads\\MediaInfo_CLI_0.7.72_Windows_x64\\MediaInfo.exe";
final ProcessBuilder builder = new ProcessBuilder(exePath, mediaPath);
builder.redirectErrorStream();
final Process process = builder.start();

final StringBuilder buffer = new StringBuilder();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
for (int i; (i = reader.read()) != -1;) {
buffer.append((char) i);
}
}

final int status = process.waitFor();
if (status == 0) {
return buffer.toString();
}

throw new IOException("Unexpected exit status " + status);
}

public static void main(final String[] args) throws Exception {

final String mediaPath = "\\\\192.168.75.25\\Data\\sd\\videos\\Argentina\\2014\\Primera_A\\Arsenal_de_Sarandí_vs._Banfield\\937560_0\\Arsenal_de_Sarandí_vs._Banfield.mp4";

final String data = Example5.executeMediaInfo(mediaPath);
final MediaInfo mediaInfo = MediaInfo.parse(data);
System.out.println(mediaInfo);
System.out.println("Done");
}
}

0 comments on commit e674f3d

Please sign in to comment.