There is a dialogue where video processing takes place by pressing, namely the picture from the video should be extracted. But it knocks out an error, there are suspicions that the showAddVideoDialog method incorrectly declared the uploadImageFromLink method, because it is at the moment of try catch and indicates, please tell me where I am.

private void showAddVideoDialog(){ AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle("Добавить видео"); View viewInflated = LayoutInflater.from(getContext()).inflate(R.layout.view_layout_add_video, (ViewGroup) getView(), false); final EditText input = (EditText) viewInflated.findViewById(R.id.edt_videoUrl); builder.setView(viewInflated); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { uploadImageFromLink(); } catch (IOException e) { e.printStackTrace(); } Toast.makeText(getContext(), "ОК", Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); Toast.makeText(getContext(), "Отмена", Toast.LENGTH_SHORT).show(); } }); builder.show(); } String youtubeUrl="youtube.com"; private void uploadImageFromLink() throws IOException { Document videoPage = Jsoup.connect(youtubeUrl).get(); Element videoIdMeta = videoPage.select("div[itemtype=http://schema.org/VideoObject] meta[itemprop=videoId]").first(); if (videoIdMeta == null) { } else { String videoId = videoIdMeta.attr("content"); String videoImageUrl = String.format("https://i.ytimg.com/vi/%s/hqdefault.jpg", videoId); Connection.Response response = null; try { response = Jsoup .connect(videoImageUrl) .ignoreContentType(true) .execute(); } catch (IOException e) { e.printStackTrace(); } Bitmap bmp = BitmapFactory.decodeStream(new ByteArrayInputStream(response.bodyAsBytes())); } } 
  • and you can see the error directly? - Alex Chermenin Sep.
  • java.lang.IllegalArgumentException: Malformed URL: youtube.com but now I understand that the error in the string ... and what then to register there? (did by example) - Inkognito
  • @Inkognito, you have an incorrect address. At least there is no protocol http:// - YuriySPb
  • @ Yuriyyyyyy, well, if the links will be taken only from YouTube, then http: // youtube.com/ one way or another by? ( - Inkognito
  • @Inkognito, like, everything is correct - YuriySPb

0