我希望能够从后台代理播放音频文件(基本上是声音)。我使用以下两种方法:
1)
SoundEffectInstance ClockTickInstance;
StreamResourceInfo ClockTickStream;
SoundEffect ClockTickSound;
try {
ClockTickStream = Application.GetResourceStream(new Uri(
@"AudioFiles/NewHighScore.wav", UriKind.Relative));
ClockTickSound = SoundEffect.FromStream(ClockTickStream.Stream);
ClockTickInstance = ClockTickSound.CreateInstance();
ClockTickInstance.IsLooped = true;
ClockTickInstance.Volume = 1.0f;
ClockTickInstance.Pitch = 1.0f;
ClockTickInstance.Play();
ClockTickInstance.Stop();
}
OR
2)
var localFolder = Package.Current.InstalledLocation;
Stream fileStream = await localFolder.OpenStreamForReadAsync("NewHighScore.wav");
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, System.Convert.ToInt32(fileStream.Length));
fileStream.Close();
SoundEffect soundefct = new SoundEffect(buffer, 16000, AudioChannels.Mono);
FrameworkDispatcher.Update();
soundefct.Play();
当我从xaml.cs文件(即来自前台应用程序)运行代码时,evrything工作正常并播放声音。
但是从后台代理程序运行代码但没有听到声音。
可能是什么问题?
以下文章显示了应用程序在后台运行时可以使用的API列表 - http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662941(v=vs.105).aspx