我希望能够从后台代理播放音频文件(基本上是声音)。我正在使用以下两种方法:
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();
}
或者
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