嗨,对不起,我不擅长英语。我意识到一个javafx jxbrowser项目,我仍然是一个新手,简而言之,在我的项目中,我在执行我的javascript脚本时遇到了一个问题,它没有运行。我遵循了这个站点上使用jquery (https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013725-working-with-jquery)的说明,但是没有什么工作--我可以说这是一个访问媒体的问题--因为我的javascript代码允许从浏览器对象访问计算机的媒体。代码在chrome上工作,而在jxbrowser上不工作。
请看我的代码,如果可能的话,纠正它的工作。谢谢,这里是我的java fx代码,有主文件,html代码和脚本javaScript (我没有放置.css文件,因为它太长了,并且不会对代码造成任何问题,因为.html文件在chrome上工作得很好)
Main.java
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
StackPane pane = new StackPane();
pane.getChildren().add(view);
Scene scene = new Scene(pane,500,400);
primaryStage.setScene(scene);
primaryStage.show();
browser.addLoadListener(new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
event.getBrowser().executeJavaScript("$('button').hide();") }
}});
InputStream urlStream = getClass().getResourceAsStream("/html/index.html");
String html = null;
try (BufferedReader urlReader = new BufferedReader(new InputStreamReader (urlStream))) {
StringBuilder builder = new StringBuilder();
String row;
while ((row = urlReader.readLine()) != null) {
builder.append(row);
}
html = builder.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
browser.loadHTML(html);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
} }
index.html
<html>
<head>
<title> boilerplate </title>
<link rel="stylesheet" href="style.css"/>
<style>
body{
padding-top: 5rem;
}
</style>
</head>
<body>
<nav class="navbar navbar-fixed-top navbar-dark bg-inverse">
<a class = "navbar-brand" href="#"> Demo wertc </a>
</nav>
<div class = "container">
<div class = "row">
<div class="col-sm-6">
<h2>Reception</h2>
<video id="receiver-video" width="100%"height="400px"></video>
<p>
<button id="start">start the connection </button>
</p>
</div>
<div class="col-sm-6">
<h2>Envoi</h2>
<video id="emitter-video" width="100%"height="400px"></video>
</div>
</div>
<script src= "app.js"></script>
</body>
</html>app.js
document.querySelector('#start').addEventListener('click',function(e){
navigator.getUserMedia({
video: true,
audio: true
},function (stream) {
let emitterVideo = document.querySelector('#emitter-video')
emitterVideo.src=window.URL.createObjectURL(stream)
emitterVideo.play()
}, function () {
})
})发布于 2018-05-03 12:13:09
此外,我建议您查看允许使用Chromium调试加载网页的远程调试端口功能。
https://stackoverflow.com/questions/50121632
复制相似问题