Bonsoir,

mon problème c'est quand checkbox plusieurs dans listview1. j'arrive pas télécharger une vidéo une à la fois.

mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
If ListView1.CheckedItems.Count > 0 Then
                Dim Folder As New FolderBrowserDialog With {
            .Description = "Veuillez choisir un dossier destionation pour télécharger les video(s) !",
            .ShowNewFolderButton = True,
            .RootFolder = Environment.SpecialFolder.Desktop}
                If Folder.ShowDialog = DialogResult.OK Then
                    For Each Item As ListViewItem In ListView1.CheckedItems
                        DownloaderVideo(Item.SubItems(1).Text, Item.Text, Folder.SelectedPath, ListView1.CheckedItems.Count)
                    Next
                    Download.Show()
                Else : Exit Sub
                End If
            Else
                MsgBox("Veuillez cocher une ou plusieur video", MsgBoxStyle.Critical, "Attention !!!")
            End If
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Private Sub DownloaderVideo(URL As String, Names As String, destination As String, Total As Integer)
Task.Factory.StartNew(Sub()
                                  Try
                                      Dim request As HttpWebRequest = CType(WebRequest.Create(New Uri(URL)), HttpWebRequest)
                                      With request
                                          .Method = "GET"
                                          .Timeout = 20000
                                          .UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0"
                                      End With
                                      Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
                                          If response.StatusCode = HttpStatusCode.OK Then
                                              Dim counter As Integer = 1
                                              Dim _ContentLenght As Integer = response.ContentLength
                                              Using stream As Stream = response.GetResponseStream()
                                                  Using fs As New FileStream(Path.Combine(destination, Names & Path.GetExtension(URL)), FileMode.Create, FileAccess.Write, FileShare.Write)
                                                      Dim _TotalBytesReceived As Integer = 0
                                                      Dim bufferSize As Long = 4096
                                                      Dim buffer As Byte() = New Byte(bufferSize - 1) {}
                                                      Dim isRead As Boolean = True
                                                      Do
                                                          Dim readedBytes As Integer = stream.Read(buffer, 0, buffer.Length)
                                                          If readedBytes = 0 Then
                                                              isRead = False
                                                              Continue Do
                                                          End If
                                                          _TotalBytesReceived += readedBytes
                                                          fs.Write(buffer, 0, readedBytes)
                                                          Me.BeginInvoke(New TotalInfoDelegate(AddressOf SetInfoVideo), counter, Total) '<= total de vidéo télécharger
                                                          Me.BeginInvoke(New ResponseInfoDelegate(AddressOf SetResponseInfo), Names, _TotalBytesReceived, _ContentLenght)
                                                      Loop While isRead
                                                      counter += 1
                                                  End Using
                                              End Using
                                          End If
                                      End Using
                                      Me.Invoke(New DoneDelegate(AddressOf DownloadValide), True) '<= une fois finie de télécharger
                                  Catch ex As WebException
                                      Me.Invoke(New DoneDelegate(AddressOf DownloadValide), False) '<= affiche une erreur avant de télécharger
                                  End Try
                              End Sub)
    End Sub
Pouvez-vous m'aider à télécharger une vidéo à la fois. Merci d'avance