|
174
|
Programación / .NET (C#, VB.NET, ASP) / Re: Como descargo un archivo de internet ( EN PARTES ). Alguien sabe?
|
en: 25 Marzo 2010, 15:35 pm
|
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
'Creating the request and getting the response Dim theResponse As HttpWebResponse Dim theRequest As HttpWebRequest Try 'Checks if the file exist
theRequest = WebRequest.Create(Me.txtFileName.Text) theResponse = theRequest.GetResponse Catch ex As Exception
MessageBox.Show("An error occurred while downloading file. Possibe causes:" & ControlChars.CrLf & _ "1) File doesn't exist" & ControlChars.CrLf & _ "2) Remote server error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
Me.Invoke(cancelDelegate, True)
Exit Sub End Try Dim length As Long = theResponse.ContentLength 'Size of the response (in bytes)
Dim safedelegate As New ChangeTextsSafe(AddressOf ChangeTexts) Me.Invoke(safedelegate, length, 0, 0, 0) 'Invoke the TreadsafeDelegate
Dim writeStream As New IO.FileStream(Me.whereToSave, IO.FileMode.Create)
'Replacement for Stream.Position (webResponse stream doesn't support seek) Dim nRead As Integer
'To calculate the download speed Dim speedtimer As New Stopwatch Dim currentspeed As Double = -1 Dim readings As Integer = 0
Do
If BackgroundWorker1.CancellationPending Then 'If user abort download Exit Do End If
speedtimer.Start()
Dim readBytes(4095) As Byte Dim bytesread As Integer = theResponse.GetResponseStream.Read(readBytes, 0, 4096) ******AYUDA********
nRead += bytesread Dim percent As Short = (nRead * 100) / length
Me.Invoke(safedelegate, length, nRead, percent, currentspeed)
If bytesread = 0 Then Exit Do
writeStream.Write(readBytes, 0, bytesread)
speedtimer.Stop()
readings += 1 If readings >= 5 Then 'For increase precision, the speed it's calculated only every five cicles currentspeed = 20480 / (speedtimer.ElapsedMilliseconds / 1000) speedtimer.Reset() readings = 0 End If Loop
'Close the streams theResponse.GetResponseStream.Close() writeStream.Close()
If Me.BackgroundWorker1.CancellationPending Then
IO.File.Delete(Me.whereToSave)
Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
Me.Invoke(cancelDelegate, True)
Exit Sub
End If
Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
Me.Invoke(completeDelegate, False)
End Sub
theResponse.GetResponseStream.Read(readBytes, 0, 4096) ******AYUDA********
Donde 0 es el numero donde empieza la descarga?
|
|
|
176
|
Programación / Scripting / Saveis si este codigo se puede utilizar para megavideo?
|
en: 25 Marzo 2010, 01:13 am
|
Este codigo es util para controlar los videos en megavideo?. Supuestamente es para youtube. insertamos el video <script type="text/javascript" src="swfobject.js"></script> <div id="ytapiplayer"> Se necesita una versión de Flash Player superior a 8 y javascript, para ver este video. </div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" }; var atts = { id: "myytplayer" }; swfobject.embedSWF("http://www.youtube.com/v/VIDEO_ID&enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "425", "356", "8", null, null, params, atts); </script>
function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("myytplayer"); }
</script>
<a href="javascript:ytplayer.playVideo()">Reproducir</a> fuente : http://www.polargeek.net/controlar-videos-de-youtube-con-javascript/Ahi forma de hacerlo con megavideo?
|
|
|
|
|
|
|