December 4, 2015 Patch
Some versions of JavaFX 8 cannot play YouTube video content. Currently, for example, Java 8u66 cannot play YouTube video content, but there may be a Java 8u72 early access release.
Background
General information about playing video in JavaFX is in my answer to: Any simple (and updated) Java frames for embedding movies . This answer only applies to embedding videos on YouTube, as this seems like what interests the question.
Decision
JavaFX can play YouTube videos using the YouTube URL if you specify the URL of the WebView , not MediaPlayer .
Questions
If you just want to use the YouTube media player and not the entire YouTube page associated with it, use the location /embed , not the location /watch in the URL.
Only some videos are embedded. For example, you cannot embed a Katy Perry video because YouTube blocks its distribution in the embedded format (instead, you are invited to watch the video on YouTube, where it is only available through the YouTube Flash Player).
In JavaFX, only videos that YouTube can play in its HTML5 player can be played. This is a fairly large percentage of YouTube videos. YouTube videos that play only on YouTube Flash Player do not play in JavaFX.
Application example
The JavaFX app below plays YouTube ads for a piece of fruit.

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.web.WebView; import javafx.stage.Stage; public class VideoPlayer extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { WebView webview = new WebView(); webview.getEngine().load( "http://www.youtube.com/embed/utUPth77L_o?autoplay=1" ); webview.setPrefSize(640, 390); stage.setScene(new Scene(webview)); stage.show(); } }
source share