I am struggling with this problem of accessing the sound file (mp3) download in isolated storage to be used in Alarm ,
The problem mentioned before
I am getting this error:
BNS Error: The action request's sound uri is invalid
Please help me but remember I am using the sound file for Alarm Regarding the code it is the same as the link above.
This is download and save code of the sound file :
Public Async Function DownloadFile(url As Uri) As Task(Of Stream)
wc = New WebClient()
AddHandler wc.OpenReadCompleted, AddressOf OpenReadCompleted
AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgress
wc.OpenReadAsync(url)
Dim r As IO.Stream = Await tcs.Task
Return r
End Function
Private Sub OpenReadCompleted(sender As Object, e As OpenReadCompletedEventArgs)
If e.[Error] IsNot Nothing Then
tcs.TrySetException(e.[Error])
ElseIf e.Cancelled Then
tcs.TrySetCanceled()
Else
tcs.TrySetResult(e.Result)
Dim file As IsolatedStorageFile
file = IsolatedStorageFile.GetUserStoreForApplication()
Using Stream As IsolatedStorageFileStream = New IsolatedStorageFileStream("Sound.mp3", System.IO.FileMode.Create, file)
Dim buffer As Byte() = New Byte(1023) {}
While (e.Result.Read(buffer, 0, buffer.Length) > 0)
Stream.Write(buffer, 0, buffer.Length)
End While
End Using
End If
End Sub
Private Sub DownloadProgress(sender As Object, e As DownloadProgressChangedEventArgs)
Proind.Value = e.ProgressPercentage / 100
Proind.Text = e.ProgressPercentage.ToString & " %" & " ( " & (e.BytesReceived \ 1000).ToString & "/" & (e.TotalBytesToReceive \ 1000).ToString & " ) KB"
End Sub