2

I want when the user clicks the icon "Add Video" button, create a dialog in which he can insert a link, which he copied.

After that, pressing the "ok" button will load the page that the user entered (from youtube) and from there take a video ID. Will store everything about this element <meta itemprop =" videoId "content =" lWHKaK7Ql3k ">.

Search for ID can be advised by means JSOUP library, but I found examples of html. Once we obtain the ID, we try to get a picture.

Prompt please as it is possible to generate an image with added video and add it to the list, as shown in the screenshot. enter image description here My code with dialog:

private void showAddVideoDialog(){
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle("Add video");
    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();
            m_Text = input.getText().toString();
            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();
}

Non-sarcastic/non-condescending responses are greatly appreciated.

Community
  • 1
  • 1
Morozov
  • 4,968
  • 6
  • 39
  • 70
  • The community appreciates sincere responses only. You need not worry about that. – progyammer Sep 27 '16 at 15:00
  • 1
    If you get a youtube link e.g. https://www.youtube.com/watch?v=4XpnKHJAok8 then you already got the id: `4XpnKHJAok8` and can retrieve an image using https://i.ytimg.com/vi/[videoID]/hqdefault.jpg (https://i.ytimg.com/vi/4XpnKHJAok8/hqdefault.jpg) – Frederic Klein Sep 27 '16 at 15:30
  • @F.Klein I don't really know where/and how I should to get link and id. – Morozov Sep 27 '16 at 15:33
  • Have a look here: http://stackoverflow.com/questions/10903754/input-text-dialog-android Currently your question is too broad (it's more ore less: write me an app), try to be more specific or break the question down into multiple questions within the scope of stackoverflow's definition of fitting topics (see http://stackoverflow.com/help/on-topic and http://stackoverflow.com/help/how-to-ask) – Frederic Klein Sep 27 '16 at 15:41
  • @F.Klein thanks, but i haven't problem to create dialog. I don't understand how to work with metadata(check link/get id) – Morozov Sep 28 '16 at 07:34

2 Answers2

4

In the following answer, I assume that the user has copied a youtube URL (youtubeUrl) into your application input field.

Sample code

String youtubeUrl = ...

// Extract video ID
Document videoPage = Jsoup.connect(youtubeUrl).get();

Element videoIdMeta = videoPage.select("div[itemtype=http://schema.org/VideoObject] meta[itemprop=videoId]").first();
if (videoIdMeta == null) {
    // Unable to determine videoId ...
} else {
    String videoId = videoIdMeta.attr("content");

    // Fetch video image
    String videoImageUrl = String.format("https://i.ytimg.com/vi/%s/hqdefault.jpg", videoId);
    Connection.Response response = Jsoup //
        .connect(videoImageUrl) //
        .ignoreContentType(true) // Needed for fetching image
        .execute();

    // Load image for later use
    Bitmap bmp = BitmapFactory.decodeStream(new ByteArrayInputStream(response.bodyAsBytes()));
}

See also

Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329
1

use this URL to get image relate to youtube id https://i.ytimg.com/vi/{ID}/hqdefault.jpg

where ID is your youtube id

subrahmanyam boyapati
  • 2,836
  • 1
  • 18
  • 28