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())); } }
http://- YuriySPb ♦