-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b86f29
commit e674f3d
Showing
7 changed files
with
332 additions
and
2 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
io/How to Add Custom File Attributes/src/main/java/com/javacreed/examples/io/Example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
io/How to Read File Attributes/src/main/java/com/javacreed/examples/io/Example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
io/How to Read File Attributes/src/main/java/com/javacreed/examples/io/Example2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
io/How to Read File Attributes/src/main/java/com/javacreed/examples/io/Example3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
io/How to Read File Attributes/src/main/java/com/javacreed/examples/io/Example4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
|
||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
io/How to Read File Attributes/src/main/java/com/javacreed/examples/io/Example5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |