尝试将我自己的.wav文件播放到Toast通知c#windows 8时出错

时间:2013-05-26 18:39:10

标签: c# windows-8 windows-runtime microsoft-metro toast

我正在尝试演奏。将wav文件转换为Toast通知。我的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);         

    }

1 个答案:

答案 0 :(得分:0)

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");

应该更改为使用其中一个枚举。例如,这使用“邮件”声音进行祝酒:

toastContent.Audio.Content = ToastAudioContent.Mail;