- // transform YouTube watch URL in embed
- String youTubeVideoId = null;
- if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) {
- if ("/watch".equals(uri.getPath())) {
- Map<String, List<String>> map = NamingUtils.queryToMap(uri);
- youTubeVideoId = map.get("v").get(0);
+ // Transform watch URL in embed
+ // YouTube
+ String videoId = null;
+ if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())
+ || "youtu.be".equals(uri.getHost())) {
+ if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) {
+ if ("/watch".equals(uri.getPath())) {
+ Map<String, List<String>> map = NamingUtils.queryToMap(uri);
+ videoId = map.get("v").get(0);
+ }
+ } else if ("youtu.be".equals(uri.getHost())) {
+ videoId = uri.getPath().substring(1);
+ }
+ if (videoId != null) {
+ try {
+ uri = new URI("https://www.youtube.com/embed/" + videoId);
+ text.setText(uri.toString());
+ } catch (URISyntaxException e1) {
+ throw new IllegalStateException(e1);
+ }