N
Nu2Csharp
Guest
I am trying to validate the following code in a WinRT project :
//This is from my MainPage.xaml file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at C#, VB, and C++ project templates for Store apps
namespace HelloWorld
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public object AsynsStatus { get; private set; }
public MainPage()
{
WinRTAsyncIntro();
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
MediaElement mediaElement = new MediaElement();
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World!");
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
public void WinRTAsyncIntro()
{
IAsyncOperation<StorageFile> asyncOp = KnownFolders.MusicLibrary.GetFileAsync("Song.mp3");
asyncOp.Completed = OpCompleted;
}
private void OpCompleted(IAsyncOperation<StorageFile> asyncOp, AsyncStatus status)
{
switch (status)
{
case AsyncStatus.Completed:
StorageFile file = asyncOp.GetResults(); break;
case AsyncStatus.Canceled:
break;
case AsyncStatus.Error:
Exception exception = asyncOp.ErrorCode; break;
}
asyncOp.Close();
}
}
}
I get an access denied exception. I tried to post an image of the my error in Visual Studio, but have to wait until my account is verified. I also found a link on stackoverflow about it, but the answers did not seem to work for the OP. I can not post the link until my account is verified.
Continue reading...
//This is from my MainPage.xaml file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at C#, VB, and C++ project templates for Store apps
namespace HelloWorld
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public object AsynsStatus { get; private set; }
public MainPage()
{
WinRTAsyncIntro();
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
MediaElement mediaElement = new MediaElement();
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World!");
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
public void WinRTAsyncIntro()
{
IAsyncOperation<StorageFile> asyncOp = KnownFolders.MusicLibrary.GetFileAsync("Song.mp3");
asyncOp.Completed = OpCompleted;
}
private void OpCompleted(IAsyncOperation<StorageFile> asyncOp, AsyncStatus status)
{
switch (status)
{
case AsyncStatus.Completed:
StorageFile file = asyncOp.GetResults(); break;
case AsyncStatus.Canceled:
break;
case AsyncStatus.Error:
Exception exception = asyncOp.ErrorCode; break;
}
asyncOp.Close();
}
}
}
I get an access denied exception. I tried to post an image of the my error in Visual Studio, but have to wait until my account is verified. I also found a link on stackoverflow about it, but the answers did not seem to work for the OP. I can not post the link until my account is verified.
Continue reading...