我正在尝试在我的 wp 8 应用程序中播放 mp3,我想忘记了一些东西,你能帮忙吗
我的简化代码是这样的:
page.xaml.cs 中的代码是:
public void Play(object sender, RoutedEventArgs e)
{
if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
{
BackgroundAudioPlayer.Instance.Pause();
}
else
{
BackgroundAudioPlayer.Instance.Play();
}
}
App.xaml.cs 中的代码是:
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] files = new string[] { "song.mp3"};
foreach (var _fileName in files)
{
if (!storage.FileExists(_fileName))
{
string _filePath = "Sounds/" + _fileName;
StreamResourceInfo resource = Application.GetResourceStream(new Uri(_filePath, UriKind.Relative));
using (IsolatedStorageFileStream file = storage.CreateFile(_fileName))
{
int chunkSize = 4096;
byte[] bytes = new byte[chunkSize];
int byteCount;
while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
{
file.Write(bytes, 0, byteCount);
}
}
}
}
}
}
我可以看到我的 BackgroundAudioPlayer.Instance
状态从未改变,但我不知道为什么(播放功能被触发)