음 재미는 두 시간이었습니다. 여기 있네! 그냥 예제에서와 같이 0 바이트의 mp4 파일을 가지고 있는지 확인하십시오. 그것은 어떻게 작동하는지 꽤 중요합니다.
public class TestFrame extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
StackPane root = new StackPane();
File actualFile = new File("shelter.mov");
File emptyfile = new File("blank.mp4");
Media media = new Media(emptyfile.toURI().toString());
copyData(media, actualFile);
MediaPlayer mediaPlayer = null;
try {
mediaPlayer = new MediaPlayer(media);
} catch (Exception e) {
e.printStackTrace();
}
mediaPlayer.setAutoPlay(true);
MediaView mediaView = new MediaView(mediaPlayer);
root.getChildren().add(mediaView);
Scene scene = new Scene(root, 720, 480);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
private void copyData(Media media, File f) {
try {
Field locatorField = media.getClass().getDeclaredField("jfxLocator");
// Inside block credits:
// http://stackoverflow.com/questions/3301635/change-private-static-final-field-using-java-reflection
{
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(locatorField, locatorField.getModifiers() & ~Modifier.FINAL);
locatorField.setAccessible(true);
}
CustomLocator customLocator = new CustomLocator(f.toURI());
customLocator.init();
customLocator.hack("video/mp4", 100000, f.toURI());
locatorField.set(media, customLocator);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
static class CustomLocator extends Locator {
public CustomLocator(URI uri) throws URISyntaxException {
super(uri);
}
@Override
public void init() {
try {
super.init();
} catch (Exception e) {
}
}
public void hack(String type, long length, URI uri){
this.contentType = type;
this.contentLength = length;
this.uri = uri;
this.cacheMedia();
}
}
}
작동 방법 : 일반적으로 기본 로케이터는 콘텐츠 형식에 대한 예외를 throw하고 모두 끝납니다. Media
의 로케이터를 사용자 지정 위치로 바꾸면 수동으로 contentType, length 및 uri를 설정하면 엿보지 않고 재생할 수 있습니다.
더 많은 스택 추적을 게시 할 수 있습니까? 편집 : NVM이 원인을 발견했습니다. 'Media'는 당신이 http://pastebin.com/NkTFT2Tk를 받고있는 예외를 던지는 Locator의이 메소드를 호출합니다. –