gpt4 book ai didi

windows-phone-8 - 如何通过 URI (WP8) 访问 IsolatedStorage 中下载的声音?

转载 作者:行者123 更新时间:2023-12-04 16:16:57 24 4
gpt4 key购买 nike

我正在努力解决这个问题,即访问隔离存储中下载的声音文件 (mp3) 以用于警报,

提到的问题before

我收到这个错误:

BNS 错误: Action 请求的声音 uri 无效

请帮助我,但请记住我正在使用警报的声音文件关于代码,它与上面的链接相同。

这是声音文件的下载和保存代码:

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

最佳答案

问题是您试图将隔离存储中的文件设置为闹钟的声音,这是不允许的。只有打包成.xap的文件才能设置为报警声源:

Remarks

The Sound URI must point to a file packaged in the application’s .xapfile. Isolated storage is not supported. When the alarm is launched,the sound is played quietly and then gradually increases in volume.There is no way to modify this behavior.

来自:

Alarm.Sound Property

但是,有一种方法可以将下载的歌曲用作阿拉姆的声音。在 OpenReadCompleted 方法中,不是将下载的文件保存在独立存储中,而是使用 File.Create 方法创建一个文件,并将数据存储在那里。然后就可以使用这个文件作为闹钟声音了:

这是 C# 代码,我认为您可以轻松地将其转换为 VB:

byte[] buffer = new byte[e.Result.Length];
e.Result.Read(buffer, 0, buffer.Length);

using (var fs = File.Create("file.mp3"))
{
fs.Write(buffer, 0, buffer.Length);
}

然后,您可以将闹钟的 Sound 属性设置为:

alarm.Sound = new Uri("/file.mp3", UriKind.Relative);

关于windows-phone-8 - 如何通过 URI (WP8) 访问 IsolatedStorage 中下载的声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17662584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com