Friday, March 22, 2013
Embed Youtube video in JavaFX WebView
The code embed Youtube view in JavaFX WebView.
To load the html code from YouTube, open a browser to load Youtube with the target video, select Share -> Embed to copy the html code into content_Url.
Embed Youtube video in JavaFX WebView
package javafx_webviewyoutube;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
/**
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_WebViewYoutube extends Application {
String content_Url = "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/9bZkp7q19f0\" frameborder=\"0\" allowfullscreen></iframe>";
@Override
public void start(Stage primaryStage) {
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
webEngine.loadContent(content_Url);
StackPane root = new StackPane();
root.getChildren().add(webView);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("http://java-buddy.blogspot.com/");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
To load the html code from YouTube, open a browser to load Youtube with the target video, select Share -> Embed to copy the html code into content_Url.
Subscribe to:
Post Comments (Atom)
4 comments:
Se queda cargando el video y no reproduce no saben cual sera el problema?
Reply DeleteGracias
Thank you very much!!!!!!!!!! Great help!!!
Reply DeleteYoutube Help
Reply DeleteHi , I am using same code in our application but this code is not able to play youtube video. Application view is successfully open but after giving error message when its try to play. we are facing some this kind of error in the view section Error:- "An error occurred. Please try again later". So please let me what is the exact problem
I have above question too. So could you please tell me how to resolve that problem
Reply Delete