Barre de progression sans fin inopérante, remplacé par PictureBox et gif
little boy62
Messages postés3440Date d'inscriptionlundi 11 novembre 2013StatutMembreDernière intervention 5 juin 2023
-
Modifié le 25 oct. 2020 à 13:54
Whismeril
Messages postés18414Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 7 juin 2023
-
25 oct. 2020 à 15:23
Bonjour.
De base, je cherchais avant tout chose :
- de créer une barre de progression sans fin et de la faire défiler
- de faire les actions désirées
- d'arrêter le défilement de la dite barre.
En AutoIt, c'était relativement simple...
Mais là, je me heurte à un mur en béton armé. XD
En effet, j'ai testé divers barres de progression....
Aucune barre ne défilait.... sauf quand les actions d’après était terminées....
j'en ai eu marre, je me suis donc lancé à l'ajout d'un gif animé via un PictureBox.
Ca fonctionne, seul.
Mais dès que je rajoute du code ensuite, comme pour la barre de progression, l'image gif n'est pas animée.
=> j'enrage.^^
Premier code avec barre de défilement
Imports System.Net
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Imports System.Text.RegularExpressions
Public Class Form1
Dim dossier_res = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YTDL-FFBIN"
Dim YTDL = dossier_res & "\youtube-dl.exe"
Dim FFBIN_url = "https://ffbinaries.com/downloads"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' débyt barre de défilement
ProgressBar1.MarqueeAnimationSpeed = 100
If System.IO.Directory.Exists(dossier_res) Then System.IO.Directory.Delete(dossier_res, True)
Directory.CreateDirectory(dossier_res)
DownloadYTDL(YTDL, "https://yt-dl.org/latest/youtube-dl.exe")
DownloadFFBinaries(FFBIN_url)
Process.Start(dossier_res)
' fin barre de défilement
End Sub
Public Sub DownloadYTDL(fichier As String, lien As String)
Dim client As New WebClient
client.Credentials = New NetworkCredential()
client.DownloadFile(lien, fichier)
End Sub
Public Sub DownloadFFBinaries(lien)
Dim sb As New StringBuilder
Dim sb2 As New StringBuilder
Dim sb3 As New StringBuilder
Dim html As String
Dim web_client As WebClient = New WebClient
Using wc As New WebClient
html = wc.DownloadString(lien)
End Using
Dim regx As New Regex("<?href\s*=\s*[""'].+?[""'][^>]*?", RegexOptions.IgnoreCase)
Dim matches As MatchCollection = regx.Matches(html)
For Each match As Match In matches
If match.Value.Contains("64.zip") And match.Value.Contains("ffmpeg") Then
Dim line = match.Value.Remove(0, 6)
line = line.Remove(line.Length - 1, 1)
'match.Value.Replace("href=", "")
sb.AppendLine(line)
Exit For
End If
Next
For Each match As Match In matches
If match.Value.Contains("64.zip") And match.Value.Contains("ffprobe") Then
Dim line = match.Value.Remove(0, 6)
line = line.Remove(line.Length - 1, 1)
'match.Value.Replace("href=", "")
sb2.AppendLine(line)
Exit For
End If
Next
For Each match As Match In matches
If match.Value.Contains("64.zip") And match.Value.Contains("ffplay") Then
Dim line = match.Value.Remove(0, 6)
line = line.Remove(line.Length - 1, 1)
'match.Value.Replace("href=", "")
sb3.AppendLine(line)
Exit For
End If
Next
Dim lien_ffmpeg = sb.ToString
Dim lien_ffprobe = sb2.ToString
Dim lien_ffplay = sb3.ToString
Dim fichier_ffmpeg = dossier_res & "\ffmpeg.zip"
Dim fichier_ffprobe = dossier_res & "\ffprobe.zip"
Dim fichier_ffplay = dossier_res & "\ffplay.zip"
Dim client2 As New WebClient
client2.Credentials = New NetworkCredential()
client2.DownloadFile(lien_ffmpeg, fichier_ffmpeg)
client2.DownloadFile(lien_ffprobe, fichier_ffprobe)
client2.DownloadFile(lien_ffplay, fichier_ffplay)
End Sub
End Class
la barre défile après que toutes les actions ont été réalisées...
Code avec PictureBox
Imports System.Net
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Imports System.Text.RegularExpressions
Public Class Form1
Dim dossier_res = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YTDL-FFBIN"
Dim YTDL = dossier_res & "\youtube-dl.exe"
Dim FFBIN_url = "https://ffbinaries.com/downloads"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' débyt barre de défilement
PictureBox1.Show()
If System.IO.Directory.Exists(dossier_res) Then System.IO.Directory.Delete(dossier_res, True)
Directory.CreateDirectory(dossier_res)
DownloadYTDL(YTDL, "https://yt-dl.org/latest/youtube-dl.exe")
DownloadFFBinaries(FFBIN_url)
Process.Start(dossier_res)
PictureBox1.Hide()
' fin barre de défilement
End Sub
Public Sub DownloadYTDL(fichier As String, lien As String)
Dim client As New WebClient
client.Credentials = New NetworkCredential()
client.DownloadFile(lien, fichier)
End Sub
Public Sub DownloadFFBinaries(lien)
Dim sb As New StringBuilder
Dim sb2 As New StringBuilder
Dim sb3 As New StringBuilder
Dim html As String
Dim web_client As WebClient = New WebClient
Using wc As New WebClient
html = wc.DownloadString(lien)
End Using
Dim regx As New Regex("<?href\s*=\s*[""'].+?[""'][^>]*?", RegexOptions.IgnoreCase)
Dim matches As MatchCollection = regx.Matches(html)
For Each match As Match In matches
If match.Value.Contains("64.zip") And match.Value.Contains("ffmpeg") Then
Dim line = match.Value.Remove(0, 6)
line = line.Remove(line.Length - 1, 1)
'match.Value.Replace("href=", "")
sb.AppendLine(line)
Exit For
End If
Next
For Each match As Match In matches
If match.Value.Contains("64.zip") And match.Value.Contains("ffprobe") Then
Dim line = match.Value.Remove(0, 6)
line = line.Remove(line.Length - 1, 1)
'match.Value.Replace("href=", "")
sb2.AppendLine(line)
Exit For
End If
Next
For Each match As Match In matches
If match.Value.Contains("64.zip") And match.Value.Contains("ffplay") Then
Dim line = match.Value.Remove(0, 6)
line = line.Remove(line.Length - 1, 1)
'match.Value.Replace("href=", "")
sb3.AppendLine(line)
Exit For
End If
Next
Dim lien_ffmpeg = sb.ToString
Dim lien_ffprobe = sb2.ToString
Dim lien_ffplay = sb3.ToString
Dim fichier_ffmpeg = dossier_res & "\ffmpeg.zip"
Dim fichier_ffprobe = dossier_res & "\ffprobe.zip"
Dim fichier_ffplay = dossier_res & "\ffplay.zip"
Dim client2 As New WebClient
client2.Credentials = New NetworkCredential()
client2.DownloadFile(lien_ffmpeg, fichier_ffmpeg)
client2.DownloadFile(lien_ffprobe, fichier_ffprobe)
client2.DownloadFile(lien_ffplay, fichier_ffplay)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.Hide()
End Sub
End Class
L'image gif n'est pas animée.
Deux questions :
- Comment faire pour que la barre de défile défile à l'appui sur le bouton ?
- Comment faire pour que le gif animé (PictureBox) défile à l'appui sur le bouton ?
J'ai comme l'impression qu'il faut que la barre de progression / picturebox doit avoir un paramètre pour qu'il puisse fonctionner.
Merci de m'aider.
++
Comme un sage m'a dit : « en France, on a le droit de tout faire....
Faut juste ne pas se faire choper. »
Whismeril
Messages postés18414Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 7 juin 2023624 25 oct. 2020 à 14:20
Bonjour
c'est parce tout est exécuté dans le même thread.
Donc la progression ne commence que quand tout le code est exécuté.
Il faut que tu fasses les 2 choses dans des threads séparés.
Et de préférence la progressbar dans le thread principal, car seul ce thread a accès à l'ihm.
C'est possible qu'un thread secondaire demande une modification de l'ihm au thread principal, mais c'est se compliquer la vie, et dans ton cas ça ne me parait pas justifié.
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' débyt barre de défilement
PictureBox1.Show()
Await Task.Run(
Sub()
If System.IO.Directory.Exists(dossier_res) Then System.IO.Directory.Delete(dossier_res, True)
Directory.CreateDirectory(dossier_res)
DownloadYTDL(YTDL, "https://yt-dl.org/latest/youtube-dl.exe")
DownloadFFBinaries(FFBIN_url)
Process.Start(dossier_res)
End Sub)
PictureBox1.Hide()
' fin barre de défilement
End Sub
Ca fonctionne !
Et donc, je l'ai aussi adapté avec la barre de défilement que je voulais
Private Async Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' ProgressBar1.Style = ProgressBar1.Style.Marquee
ProgressBar1.MarqueeAnimationSpeed = 100
Await Task.Run(
Sub()
If System.IO.Directory.Exists(dossier_res) Then System.IO.Directory.Delete(dossier_res, True)
Directory.CreateDirectory(dossier_res)
DownloadYTDL(YTDL, "https://yt-dl.org/latest/youtube-dl.exe")
DownloadFFBinaries(FFBIN_url)
Process.Start(dossier_res)
End Sub)
ProgressBar1.MarqueeAnimationSpeed = 0
End Sub
Whismeril
Messages postés18414Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 7 juin 2023624 Modifié le 25 oct. 2020 à 15:24
Oui et non.
Le principal intérêt de la fabrique de thread consiste à disposer d’un stock de threads prêts à servir, c’est donc utile pour gagner du temps quand on doit enchaîner les threads.
Un autre avantage c’est que ça se code facilement.
Par contre, les erreurs d’exécution ne sont pas remontées.
Tu ne sauras pas si ton téléchargement est finit ou s’il a planté quand ça s’arrêtera.
C’est très bien décrit dans les articles de fdorin que je t’ai mis en lien
Quand j'étais petit, la mer Morte n'était que malade.
George Burns