[英]Error when trying to play my own .wav file into a toast notification c# windows 8
我想玩一個。 WAV文件成敬酒通知。 我的 “ wav文件位於我的應用程序的本地文件夾中,但不幸的是,我遇到以下異常:System.ArgumentException”未找到請求的值'ms-appdata:////local/archivo.wav'。“ 有人可以幫助我嗎? 這是我保存文件的代碼
private async void guardarArchivo()
{
speak = new SpeechSynthesizer(idCliente, ClientSecret);
speak.AudioFormat = SpeakStreamFormat.MP3;
speak.AudioQuality = SpeakStreamQuality.MaxQuality;
// audio stream
Nstream = await speak.GetSpeakStreamAsync(txtnota.Text, "es");
inputStream = Nstream.GetInputStreamAt(0);
DataReader datareader = new DataReader(inputStream);
await datareader.LoadAsync((uint)Nstream.Size);
byte[] buffer = new byte[(int)Nstream.Size];
datareader.ReadBytes(buffer);
var folder = Windows.Storage.ApplicationData.Current.LocalFolder;//Obtenemos el folder local donde se encuentra alojada la app
var option = Windows.Storage.CreationCollisionOption.OpenIfExists;//Si no existe el archivo lo crea , si existe no pasa nada , solo sobrescribre
//Creamos el archivo
var archivo = await folder.CreateFileAsync("archivo.wav", option);
await FileIO.WriteBytesAsync(archivo, buffer);
}
這是我嘗試創建Toast通知的代碼
private void btncrearclick(object sender, RoutedEventArgs e)
{
var toastContent = NotificationsExtensions.ToastContent.ToastContentFactory.CreateToastText01();
toastContent.TextBodyWrap.Text =txtnota.Text;
toastContent.Duration = ToastDuration.Long;
//here is the error
toastContent.Audio.Content = (ToastAudioContent)Enum.Parse(typeof(ToastAudioContent),"ms-appdata:///local/archivo.wav");
var toast = toastContent.CreateNotification();
ScheduledToastNotification toastnotificacion = new ScheduledToastNotification(toastContent.GetXml(), new DateTimeOffset(DateTime.Now.AddSeconds(5)));
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.AddToSchedule(toastnotificacion);
}
Toast Extensions代碼當前不允許您指定自己的文件。
您必須使用以下枚舉之一:
public enum ToastAudioContent
{
Default = 0,
Mail,
SMS,
IM,
Reminder,
LoopingCall,
LoopingCall2,
LoopingAlarm,
LoopingAlarm2,
Silent
}
因此,此行在您的代碼中:
toastContent.Audio.Content = (ToastAudioContent)
Enum.Parse(typeof(ToastAudioContent),"ms-appdata:///local/archivo.wav");
應該更改為使用枚舉之一。 例如,這將“ Mail”聲音用於烤面包:
toastContent.Audio.Content = ToastAudioContent.Mail;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.