Chciałbym przerobić kod programiku z VB.NET na C# którego działaniem jest pobierania miniaturki filmu z YouTube do Picture Box, chcę to zamieścić do swego programu. Zamieszczam screen oraz download jeśli by ktoś chciał zobaczyć:
Download z załącznikach a tu jest skan:
Public Class MainForm
Private Sub getThumbailButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles getThumbailButton.Click
Dim urlQueryStrPos As Integer
'Lets find the index of the query string ?v=
'right after the equal sign would be the youtube video id which is
'an 11-character string generated by youtube when a user uploads a video.
urlQueryStrPos = Me.youtubeURL.Text.IndexOf("?v=")
If urlQueryStrPos < 0 Then MessageBox.Show("Please enter a valid url.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) : Exit Sub
Dim youTubeVideoIdStartPos As Integer
youTubeVideoIdStartPos = urlQueryStrPos + 3 'locate the start position of the video ID
Dim youtubeVideoId As String
youtubeVideoId = Me.youtubeURL.Text.Substring(youTubeVideoIdStartPos, 11) 'extract the video id from the url string
Dim smallThumbnailUrl As String
Dim largeImageUrl As String
Dim alternateThumbnailOneUrl As String
Dim alternateThumbnailTwoUrl As String
'The Thumbnail Images can be previewed by visiting the following URLS:
'http://img.youtube.com/vi/<videoid>/default.jpg
'
'Just replace <videoid> with the real video id
'default.jpg - default thumbnail
'0.jpg - large image preview (480px x 360px)
'1.jpg - Alternate thumbnail
'3.jpg - Alternate thumbnail
smallThumbnailUrl = "http://img.youtube.com/vi/" & youtubeVideoId & "/default.jpg"
largeImageUrl = "http://img.youtube.com/vi/" & youtubeVideoId & "/0.jpg"
alternateThumbnailOneUrl = "http://img.youtube.com/vi/" & youtubeVideoId & "/1.jpg"
alternateThumbnailTwoUrl = "http://img.youtube.com/vi/" & youtubeVideoId & "/3.jpg"
Me.smallThumbnail.Load(smallThumbnailUrl)
Me.largeImage.Load(largeImageUrl)
Me.alternateThumbOne.Load(alternateThumbnailOneUrl)
Me.alternateThumbTwo.Load(alternateThumbnailTwoUrl)
End Sub
End Class
na C# zrobiłem coś takiego lecz nie działa dodałem wszystko co trzeba text box picture box button lecz nic się nie dzieje, brak reakcji:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
//Description: This program can be used to preview youtube video thumbnails
//Author: Arjay C. Nacion
//Date:January 11, 2010
public class MainForm
{
private void getThumbailButton_Click(System.Object sender, System.EventArgs e)
{
int urlQueryStrPos = 0;
//Lets find the index of the query string ?v=
//right after the equal sign would be the youtube video id which is
//an 11-character string generated by youtube when a user uploads a video.
urlQueryStrPos = this.youtubeURL.Text.IndexOf("?v=");
if (urlQueryStrPos < 0){MessageBox.Show("Please enter a valid url.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);return;
}
int youTubeVideoIdStartPos = 0;
youTubeVideoIdStartPos = urlQueryStrPos + 3;
//locate the start position of the video ID
string youtubeVideoId = null;
youtubeVideoId = this.youtubeURL.Text.Substring(youTubeVideoIdStartPos, 11);
//extract the video id from the url string
string smallThumbnailUrl = null;
string largeImageUrl = null;
string alternateThumbnailOneUrl = null;
string alternateThumbnailTwoUrl = null;
//The Thumbnail Images can be previewed by visiting the following URLS:
//http://img.youtube.com/vi/<videoid>/default.jpg
//
//Just replace <videoid> with the real video id
//default.jpg - default thumbnail
//0.jpg - large image preview (480px x 360px)
//1.jpg - Alternate thumbnail
//3.jpg - Alternate thumbnail
smallThumbnailUrl = "http://img.youtube.com/vi/" + youtubeVideoId + "/default.jpg";
largeImageUrl = "http://img.youtube.com/vi/" + youtubeVideoId + "/0.jpg";
alternateThumbnailOneUrl = "http://img.youtube.com/vi/" + youtubeVideoId + "/1.jpg";
alternateThumbnailTwoUrl = "http://img.youtube.com/vi/" + youtubeVideoId + "/3.jpg";
this.smallThumbnail.Load(smallThumbnailUrl);
this.largeImage.Load(largeImageUrl);
this.alternateThumbOne.Load(alternateThumbnailOneUrl);
this.alternateThumbTwo.Load(alternateThumbnailTwoUrl);
}
}